Hello there, I've been having problems creating a part of my mail system that makes messages look red when they haven't been read, and white when they have been read.

This is what I'm using right now

mysql_query("UPDATE Mail SET Read=1 WHERE ID={$messageID}");

The SQL ID Field is a smallint and the PHP variable $messageID is an int too.
The error it's displaying 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=20' at line 1

Please help me find what's wrong in my code!

Edited by GigsD4X: n/a

7 Years
Discussion Span
Last Post by drjohn

OMG! I found the problem! Thanks for not helping me people!

Now I shall post the solution so people who are looking for the same answer I was know how to fix it.

Apparently, on the SQL manual, I found this!

Some words, like To, Read, Write, etc., are interpreted like something else, so you have to put ` signs around them.

So basically, this is the fixed code.

mysql_query("UPDATE Mail SET `Read`='1' WHERE `ID`={$messageID};");

Notice the ` signs around Read and ID?

So just put them on every column name to prevent problems like these!
Also I recommend using {} signs around PHP variables.


Every language has certain terms, called reserved words, that have a specific meaning. The answer is simple - do NOT use these words for anything other than their intended meaning. eg you would not give a column in a database the name table or create or if or while as these are reserved words. You should really rename the column to something else rather than use the ' ' around it. It is VERY bad practice to use reserved words as column names or variable names. It is likely to cause you problems.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.