brem13 Posted May 31, 2009 Share Posted May 31, 2009 i keep getting this error when trying to update a table in my 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 'like = 1 WHERE id = 2' at line 1 code $like = htmlspecialchars($_GET['likes']); $id = htmlspecialchars($_GET['id']); $category = htmlspecialchars($_GET['category']); if($like <= 0 || $like == ""){ $like = 1; mysql_connect('*********', '*******', '***********') or die (mysql_error()); mysql_select_db('********') or die ("Could not select database because ".mysql_error()); mysql_query("UPDATE $category SET like = $like WHERE id = $id") or die("Could not insert data because ".mysql_error()); mysql_close(); }//end if ive been trying to fix this for over an hour, someone please help Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/ Share on other sites More sharing options...
phpretard Posted May 31, 2009 Share Posted May 31, 2009 Change your htmlspecialchars to striplslashes Then insert them with htmlspecialchars $like = striplslashes($_GET['likes']); update table set Like='$like' where ... Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846048 Share on other sites More sharing options...
brem13 Posted May 31, 2009 Author Share Posted May 31, 2009 nope, same thing Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846049 Share on other sites More sharing options...
phpretard Posted May 31, 2009 Share Posted May 31, 2009 Can you post $like or an example of it? Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846050 Share on other sites More sharing options...
phpretard Posted May 31, 2009 Share Posted May 31, 2009 ("UPDATE $category SET like = '$like' WHERE id = '$id' ") Single quotes around you variables...I didn't see that before Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846051 Share on other sites More sharing options...
brem13 Posted May 31, 2009 Author Share Posted May 31, 2009 like is 0 i've echoed all the variables and they all show fine this if statement should take like if like=0 and make the like field in the table = 1. i have an elseif statement underneath it, that checks if like>0 and if it is, it will add 1 to the total of like and in turn update the field in the table oh, and i've tried the single quotes, i get the same error Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846053 Share on other sites More sharing options...
phpretard Posted May 31, 2009 Share Posted May 31, 2009 I think like is a mysql keyword so have to use the weirdo single quotes ("UPDATE $category SET `like` = '$like' WHERE id = '$id' ") I would personly rename the DB field "like_it" or "love" Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846054 Share on other sites More sharing options...
brem13 Posted May 31, 2009 Author Share Posted May 31, 2009 thanks a lot, u fixed it, it was those backticks grrrrrrr, lol. thank you Quote Link to comment https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/#findComment-846057 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.