Styles2304 Posted August 26, 2007 Share Posted August 26, 2007 Ok, here's the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 And then here's the code: <?php include "auth.inc.php"; include "conn.inc.php"; //Defines variables $IndexNo = $_POST['IndexNo']; $PAccess = $_POST['PAccess']; $EventDate = $_POST['EventDate']; $Title = $_POST['Title']; $DisplayTitle = $_POST['DisplayTitle']; $Body = $_POST['Body']; //Sets up new query to enter variables into database $query = "UPDATE CalendarEvents SET " . "EventDate = '" . $EventDate . "', " . "Title = '" . $Title . "', " . "CalendarDisplayTitle = '" . $DisplayTitle . "', " . "Body = '" . $Body . "', " . "PublicAccess = '" . $PAccess . "' WHERE IndexNo = " . $IndexNo . ""; mysql_query($query,$link) or die(mysql_error()); header('Location: calendar.php'); ?> See anything wrong? I've been staring at it too long to notice. Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/ Share on other sites More sharing options...
pocobueno1388 Posted August 26, 2007 Share Posted August 26, 2007 Use mysql_real_escape_string() on all your variables. EX: $IndexNo = mysql_real_escape_string($_POST['IndexNo']); Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334197 Share on other sites More sharing options...
AV1611 Posted August 26, 2007 Share Posted August 26, 2007 $query = "UPDATE CalendarEvents SET `EventDate`= '$EventDate', `Title` = '$Title',`CalendarDisplayTitle` = '$DisplayTitle', `Body` = '$Body', `PublicAccess` = '$PAccess' WHERE `IndexNo` = '$IndexNo'"; Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334199 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 U have no quotes at WHERE IndexNo = '$IndexNo'. And why use string concatination (however it is written) when u can write it in a single string, and also make it proccess faster: "UPDATE CalendarEvents SET EventDate='$EventDate', Title='$Title' etc etc"; Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334205 Share on other sites More sharing options...
AV1611 Posted August 26, 2007 Share Posted August 26, 2007 U have no quotes at WHERE IndexNo = '$IndexNo'. And why use string concatination (however it is written) when u can write it in a single string, and also make it proccess faster: "UPDATE CalendarEvents SET EventDate='$EventDate', Title='$Title' etc etc"; Um, that's what I said Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334208 Share on other sites More sharing options...
Fadion Posted August 26, 2007 Share Posted August 26, 2007 Um, that's what I said lol yeah i know but i highlighted it for him to understand it better Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334210 Share on other sites More sharing options...
Styles2304 Posted August 26, 2007 Author Share Posted August 26, 2007 Ok well . . . that's not the problem . . . $IndexNo isn't a string, it's a int so it doesn't need quotes. Here's a chunk of code that's almost identical that works. <?php include "auth.inc.php"; include "conn.inc.php"; //Defines variables $IndexNo = $_POST['IndexNo']; $EntryDate = $_POST['EntryDate']; $DelDate = $_POST['DeleteDate']; $OnGoing = $_POST['OnGoing']; $PAccess = $_POST['PAccess']; $Announcement = $_POST['Announcement']; //Sets up new query to enter variables into database $query = "UPDATE Announcements SET " . "EntryDate = '" . $EntryDate . "', " . "Data = '" . $Announcement . "', " . "OnGoing = '" . $OnGoing . "', " . "DeleteDate = '" . $DelDate . "', " . "PublicAccess = '" . $PAccess . "' WHERE IndexNo = " . $IndexNo . ""; mysql_query($query,$link) or die(mysql_error()); header('Location: announcements.php'); ?> I pretty much just copy and pasted the code and changed the name of the variables. While comparing the two, can you guys see where the error is . . . because I can't and the second one definitely works. Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334212 Share on other sites More sharing options...
Styles2304 Posted August 26, 2007 Author Share Posted August 26, 2007 Alright nevermind . . . a stupid error. It was supposed to be $_SESSION['IndexNo'] not $_POST . . . thanks for the help anyways. Link to comment https://forums.phpfreaks.com/topic/66705-solved-always-syntax-errors-with-me/#findComment-334215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.