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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.