title: Filtering SQL queries with php, and html select boxes
body: <p>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.</p>
  
  <pre><code>&lt;select name="price" size="0"&gt;
  &lt;option value="100000"&gt;Under $100,000&lt;/option&gt;
  &lt;option value="&lt;?php echo " BETWEEN '100000' AND '250000' "?&gt;"&gt;Between $100,000 and $250,000&lt;/option&gt;
  &lt;option value="&gt;250000&lt;500000"&gt;Between $250,000 and $500,000&lt;/option&gt;
  &lt;option value="&gt;500000&lt;750000"&gt;Between $500, 000 and $750,000&lt;/option&gt;
  &lt;option value="&gt;7500000"&gt;Over $750,000&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>This is my $_POST statement for the price variable: </p>
  
  <pre><code>$price = mysql_real_escape_string($_POST['price']);
  </code></pre>
  
  <p>This is my sql statement:</p>
  
  <pre><code>$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'");
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>"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'"`
  </code></pre>
  
  <p>However i get this error:</p>
  
  <p>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</p>
  
  <p>Any ideas as to where i went wrong? Thanks</p>
  
  <p>Regards,
  D. Ruddock</p>