View Full Version : Insert query syntax help
09-06-2011, 11:40 PM
When you have been away from coding it is struggle. My thanks to those who have helped. Obviously, since I get an error, I have one too many or too few single or double quotes. Please help.
$sql = "INSERT INTO " . WP_CALENDAR . " SET event_title='" . mysql_escape_string($title) . "', event_desc='" . mysql_escape_string($desc) . "', event_begin='" . mysql_escape_string($start_date)
. "', event_end='" . mysql_escape_string($end_date) . "', event_time='" . mysql_escape_string($game_time) . "', event_recur='" . mysql_escape_string($recur) . "', event_repeats='" . mysql_escape_string($repeat) . "', event_author='" mysql_escape_string($author) . "', event_category=".mysql_escape_string($category).", event_link='".mysql_escape_string($link)."'";
09-07-2011, 12:14 AM
First of all, read this page:
See the big "DEPRECATED" there?
But beyond that: Why would you want to treat dates and times ($start_date, $game_time) as *TEXT*? SURELY those values are DATETIME or TIMESTAMP fields in your database, no? So treat them as such. And are the fields such as event_recur and event_repeat really *text* fields in the table? Or are they numbers? If numbers, treat them as numbers.
As an aside, it strikes me as bad practice to have multiple tables with the same data structure, as is implied by the fact that the table name is a variable in your code. Or at least it seems that way. How come WP_CALENDAR isn't a PHP variable? That is, $WP_CALENDAR or similar? Where is it coming from ?
09-07-2011, 12:27 AM
Quite honestly, I don't see the error.
Unless it's the missing $ in front of WP_CALENDAR????
I think I might have coded it thus, though, for clarity:
$title = mysql_real_escape_string($title);
$desc = mysql_real_escape_string($desc);
$start_date = date("Y-m-d",$start_date);
$end_date = date("Y-m-d",$end_date);
$game_time = date("h:i:s",$game_time); /* PURE GUESS ON THIS ONE! */
$recur = mysql_real_escape_string($recur);
$repeat = mysql_real_escape_string($repeat);
$author = mysql_real_escape_string($author);
$category = 1 * $category; /* force to be a number! */
$link = mysql_real_escape_string($link);
$sql = "INSERT INTO " . WP_CALENDAR
. "(event_title, event_desc, event_begin, event_end, "
. "event_time, event_recur, event_repeats, event_author, "
. "event_category, event_link) "
. " VALUES('$title$','$desc','$start_date','$end_date', "
. "'$game_time','$recur','$repeat','$aughor', "
echo "<hr>DEBUG SQL: " . $sql . "<hr>\/n";
09-07-2011, 08:07 PM
Please post the error its giving you. That will tell exactly what the problem is. I have a hunch it's a variable problem.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.