I am creating a search form for real estate site which is working fine but I have added two more fields min and max price. When I hard code the value in PHP MySQL query, it shows correct results and even though when I define the variable and write the price value in variables it is working fine but when I get values from select box, the form is not showing results, although I have tested the variables by echo and values of variables echo successfully but not working in query.
Following is my code for getting value from form submit. I am using post method for form submission and using same page search.php as a form and as a submit to action.
if(!empty($_POST['0']))
{
$value1 = mysql_real_escape_string($_POST['value1']);
}
else
{
$value1 = "";
}
if(!empty($_POST['value2']))
{
$value2 = mysql_real_escape_string($_POST['value2']);
}
else
{
$value2 = "";
}
Here is my PHP MySQL query:
$sql = mysql_query("SELECT listing.id, listing.title, listing.city, listing.state, listing.zip, listing.price FROM listing, property_types WHERE listing.id = property_types.listing_id AND listing.city LIKE '%$city%' AND listing.zip LIKE '%$zip%' AND property_types.prop_type LIKE '%$property_type%' AND listing.beds LIKE '%$beds%' AND listing.baths LIKE '%$baths%' AND listing.motorcycles LIKE '%$motorcycles%' AND listing.number_of_pets LIKE '%$pets%' AND listing.price BETWEEN '$value1' AND '$value2'");