I’ve got a simple SQL query that keeps throwing an SQL syntax error. It looks like this:
$sql = "SELECT COUNT(*) AS TOTAL FROM PRODUCT WHERE ID_PRODUCT = ".$id;
$result = mysql_query($sql) or die(mysql_error());
Which throws :
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 ‘WHERE
ID_PRODUCT = 1’ at line 1
I don’t understand what’s going on. Of course if I try the query directly in phpMyAdmin it works with no problem.
It returns exactly the same error with a SELECT *
Edit: ID_PRODUCT is a foreign key…
Update: I also get the same error when replacing the $id variable by a static value in the $sql string WHERE ID_PRODUCT = 2 and when protecting the names by quotes.
Try completely retyping your
$sqlline by hand, you might accidentally have an invisible extended character in there (such as a non-breaking space instead of a regular space, etc).