I am developing a website where by people can buy and sell new or used cars. I want to set up a simple filter using php and sql statements and also of course html select boxes (drop down options). I have gotten all the other options to work with help and trust me it has been greatly appreciated. However i have been trying to get the "price filter" to work and been getting no where. Below is what my select box in html look like.
<select name="price" size="0">
<option value="100000">Under $100,000</option>
<option value="<?php echo " BETWEEN '100000' AND '250000' "?>">Between $100,000 and $250,000</option>
<option value=">250000<500000">Between $250,000 and $500,000</option>
<option value=">500000<750000">Between $500, 000 and $750,000</option>
<option value=">7500000">Over $750,000</option>
</select>
This is my $_POST statement for the price variable:
$price = mysql_real_escape_string($_POST['price']);
This is my sql statement:
$sql = sprintf("SELECT * FROM `chjadb_vehicles` WHERE `v_make` LIKE '$make'AND `v_year` = '$year'AND `v_trans` LIKE '$trans'AND `condition` LIKE '$cond' AND `b_style` LIKE '$b_style' AND `v_price` '$price'");
After which i have a basic loop that should print the results. Now from what i understand (correct or not), when the user selects a specific option from the drop down menu the value from "option value" is passed to the $_POST statement. After which it should replace $price with the actual text BETWEEN '100000' AND '250000', completing the query statement. So the final statement printed from the sql statement should be:
"SELECT * FROM `chjadb_vehicles` WHERE `v_make` LIKE '$make'AND `v_year` = '$year'AND `v_trans` LIKE '$trans'AND `condition` LIKE '$cond' AND `b_style` LIKE '$b_style' AND `v_price` BETWEEN '100000' AND '250000'"`
However i get this error:
BETWEEN \'100000\' AND \'250000\' 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 '' BETWEEN \'100000\' AND \'250000\' '' at line 8
Any ideas as to where i went wrong? Thanks
Regards, D. Ruddock
WHERE v_price >= 100000 AND v_price <= 250000?v_price<= 250000'' at line 8