0

My query code is:

$query = mysql_query("UPDATE books SET read = 'y' WHERE id = 2") or die(mysql_error());

and the error is:

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 'read = 'y' WHERE id = 2' at line 1
chim
  • 8,407
  • 3
  • 52
  • 60
Gary
  • 961
  • 3
  • 9
  • 16
  • 1
    I hope your `read` field is an ENUM and not a VARCHAR. If it's a VARCHAR change it to `ENUM('y', 'n')` to make it nore efficient. – ThiefMaster Nov 29 '10 at 18:53
  • 1
    Additionally you can probably get rid of the `$query = ` part unless you need the return value (to check the number of affected rows or something similar). – ThiefMaster Nov 29 '10 at 18:54

1 Answers1

3

read is a reserved keyword in MySQL. Enclose it in backticks:

UPDATE books SET `read` = 'y' WHERE id = '2'

See http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html for a list of reserved keywords.

ThiefMaster
  • 310,957
  • 84
  • 592
  • 636