Skip navigation links

MySQL Forums :: Newbie :: 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


Advanced Search

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
Posted by: Simon Todd ()
Date: May 23, 2010 03:33AM

I have the following code

$subcat=$_POST['subcat'];
$results=array();
$result=mysql_query("SELECT * FROM `subcategory` where `subcategory`=$subcat") or die(mysql_error());
while($a_row = mysql_fetch_array($result, MYSQL_ASSOC)) array_push($results, $a_row);

I have verfified that $subcat is presenting a correct value by echoing it onto the screen, but this is where the problem is, for example, the echo reports it returns this value from the database which is correct:

'145 1.9JTD 105 BHP' or another Example would be "A4,1.9TDI,130 BHP"

But when the mySQL query is ran the following message is displayed

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 '1.9JTD 105 BHP' at line 1

or the other example
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 '1.9TDI,130 BHP' at line 1

For some reason it is removing the first section of the value, and then the database produces a returned value of 0

Any ideas why? I am using MySQL 5

Options: ReplyQuote


Subject Written By Posted
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 Simon Todd 05/23/2010 03:33AM
Re: 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 laptop alias 05/23/2010 04:43AM
Re: 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 Simon Todd 05/23/2010 12:08PM
Re: 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 Rick James 05/23/2010 11:03AM
Re: 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 Simon Todd 05/23/2010 11:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.