I have the following query to update a database table from a form and when I run it, I get a syntax error.
$query = "UPDATE dues SET jan=’$jan’, feb=’$feb’, mar=’$mar’, apr=’$apr’, may=’$may’, jun=’$jun’, jul=’$jul’, aug=’$aug’, sep=’$sep’, oct=’$oct’, nov=’$nov’, dec=’$dec’ WHERE ID=$id";
$result = mysql_query($query);
when I echo mysql_error(); I get the following:
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 ‘dec=’Not Paid’ WHERE ‘ID’=1′ at line 1
I have already tried putting single quotes around $id but that didn’t fix it either, I tried removing the commas and it didn’t work either. I tried putting the values in parenthases and it didnt work. I have tried a lot of things and NOTHING has worked. I have no idea what I need to change.
I need help because I usually set up all my other update statements just like this one, (syntax-wise), but for some reason this one wont work.
If you need more details to figure it out, just let me know.
Thank You!!
DEC is a reserved word in MySQL. See: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Try ….
nov=’$nov’, ‘dec’='$dec’ WHERE ID=$id;
or, possibly better,
nov=’$nov’, dues.dec=’$dec’
If neither of those help, please print out the "real" SQL you execute and update the problem with it - it might be something that is only causing syntax problems once the variables are resolved.