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.
syntax error, unexpected T_VARIABLEbecause you are missing a semi-colon. Please provide the code you are actually using. When people debug something that isn't your code, they'll often fail to fix your code because it isn't as similar as you think it is.$id? What steps are you taking to sanitize it? Why are you using parametrized queries?