usadarts Posted August 20, 2007 Share Posted August 20, 2007 Receiving the following error: I cannot update database: "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 'WHERE `rrn` =1' at line 1 $sql = "UPDATE `homepage` SET `date` = $date, `comments` = $newcomments WHERE `rrn` =1"; Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/ Share on other sites More sharing options...
btherl Posted August 20, 2007 Share Posted August 20, 2007 $date_sql = "'" . mysql_real_escape_string($date) . "'"; $newcomments_sql = "'" . mysql_real_escape_string($newcomments) . "'"; $sql = "UPDATE `homepage` SET `date` = $date_sql, `comments` = $newcomments_sql WHERE `rrn` =1"; If you've already escaped your strings, you can skip that. But you need the single quotes around strings. Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/#findComment-328418 Share on other sites More sharing options...
Fadion Posted August 20, 2007 Share Posted August 20, 2007 $sql = "UPDATE homepage SET date='$date', comments='$newcomments' WHERE rrn='1'"; U dont need smart quotes for tables names or columns, but u need single quotes for values. Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/#findComment-328421 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 WHERE `rrn` ='1' Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/#findComment-328423 Share on other sites More sharing options...
usadarts Posted August 20, 2007 Author Share Posted August 20, 2007 Thank you all Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/#findComment-328426 Share on other sites More sharing options...
btherl Posted August 20, 2007 Share Posted August 20, 2007 Note that you should not add quotes around 1 if rrn is an integer. Quote Link to comment https://forums.phpfreaks.com/topic/65745-solved-syntax-error-during-sql-update/#findComment-328507 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.