tags:

views:

55

answers:

6

I wouldn't ask if i wasn't sure that i have 100% no idea why this isn't working, so, in PHP i'm simply trying to update a value in the MySQL database:

The field im updating - Name: read - Type: tinyint - Length: 1

Here is the PHP code:

do_SQL("UPDATE messages SET read=1 WHERE id='".$id."'");

The do_SQL function is working for everything else, so it's something wrong with this statement. I have tried putting 1 in '1' and it still didn't work.m 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=1 WHERE id='1'' at line 1

Thanks for reading!

A: 

There are no escape characters.

do_SQL('UPDATE messages SET read=1 WHERE id=\''.$id.'\'');
Nik
His string used double-quotes, so he doesn't need them
Michael Mrozek
+1  A: 

If id is numeric, try removing the quotes aka:

do_SQL("UPDATE messages SET `read` = 1 WHERE id = ".$id);
thephpdeveloper
A: 

Is 'Id' an integer?

Ev
+2  A: 

read Is a keyword in MySQL, so you can't use it without quoting it (with backticks):

do_SQL("UPDATE messages SET `read`=1 WHERE id='".$id."'");
Michael Mrozek
Ahhh! I actually searched for some kind of 'Reserved words' list but didn't find anything. Damn i hate SQL and all its annoying quotes and words and stuff... Thanks!
Tommo
@Tommo Khorkrak linked to it in [his answer](http://stackoverflow.com/questions/3066756/whats-wrong-with-this-sql-update-query/3066769#3066769); it's here: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html
Michael Mrozek
@Tommo - love SQL, you'll need it.
thephpdeveloper
+2  A: 

read is probably a reserved word in MySQL.

Yep it is MySQL Reserved Words

Next time check that list before creating a column with a name that's likely to be used already by the database system.

Khorkrak
+1  A: 

Don't quote $id. Let PHP do substitution in the string.

 do_SQL("UPDATE messages SET read=1 WHERE id=$id.");
tpdi
Thanks, this also helped :)
Tommo
@Tommo There's actually no problem with quoting numerics in an SQL statement
Michael Mrozek