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!

Re: WHERE Clause Problems with PHP 80 80

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.

Re: WHERE Clause Problems with PHP 80 80

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.