Reputation: 769
I have an MySQL error and I cannot figure it out... It was working and now it is not working anymore (I haven't done anything to the database).
Here is the query:
$querySearch = "SELECT * FROM cars WHERE (price >= {$startPrice} AND price <= $endPrice) AND condition = '{$condition}'";
Here is the form:
<h3>Condition:</h3>
<span class="searchRange">
<select name="condition" class="condition">
<option value="any">Any Condition</option>
<option value="Brand New">Brand New</option>
<option value="Near New">Near New</option>
<option value="Good">Good</option>
<option value="Ok">Ok</option>
<option value="Poor">Poor</option>
</select>
</span>
And here is how PHP receives the data:
$condition = mysql_prep($_POST['condition']);
mysql_prep()
is a user made function that just takes care of the magic quote stuff.
Anyone see where an error could occur?
Error: Database query failed: 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 'condition = 'Near New'' at line 1
Upvotes: 1
Views: 53
Reputation: 31141
Condition is a reserved keyword
Enclose it in backticks.
AND `condition` =
Upvotes: 6