this is my php query script if(isset($_GET['likeId'])){ $id = $_GET['likeId'];// suppose id $insertLike ="UPDATE studentwall SET like='hello' WHERE id={$id}"; $insertLikeQuery=mysql_query($insertLike,$con); if(!$insertLikeQuery){ die('error'.mysql_error()); } }// end if(isset($_GET['likeId'])) and this is my 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 'like='hello' WHERE id=225' at line 1 please help
Still it is not working. The table "studentwall" contains many columns like a,b,c,d and these were created a long time ago. Now When i create a new column "like" in this table and then insert value in it from the browser, the error shows : 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='hello' WHERE id=225' at line 1 But if i try updating values in the other columns like "a" with the same query aforementioned, then it works fine. But it is not working for the "like" column
That's because the data type of the "like" column and the data type of the value you're trying to enter is not the same.
You can escape reserved keywords by enclosing it with back tick character(`). Example would be: "UPDATE studentwall SET `like`='hello' WHERE id='".$id."'" Code (markup): Hope it helps