Page 1 of 1

query IS NULL error

Posted: Wed Feb 11, 2009 12:09 pm
by Doshaburi
Hello,

I have this piece of code:

Code: Select all

foreach(range("a","z") as $letter){
    $result = mysql_query("SELECT * FROM mails WHERE mail LIKE '{$letter}%' AND group IS NULL") or die("ERROR:".mysql_error());
}
And when i try to run the script it outputs this:

ERROR: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 'group IS NULL' at line 1

The 'group' field is a varchar type and is set to NULL by default.

What could be the couse of this error?

Without the "AND group IS NULL" it works fine btw.

Re: query IS NULL error

Posted: Wed Feb 11, 2009 12:26 pm
by Eran
group is a reserved word in mysql. You'd be better off changing the column name to something else, or you can quote the column name using backhand ticks:

Code: Select all

SELECT * FROM mails WHERE mail LIKE 'a%' AND `group` IS NULL

Re: query IS NULL error

Posted: Wed Feb 11, 2009 12:30 pm
by Doshaburi
thnx mate it worked like a charm :)