Jump to content

[SOLVED] error updating table :(


brem13

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/160325-solved-error-updating-table/
Share on other sites

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.