简体   繁体   中英

Search form for Prices

I have a form that is trying to search different prices. I manage to search Address and City information but with the prices no search results show up. I am not sure if its in the HTML side or the PHP side where I am going wrong. I am using 2 drop down lists with a set number of price ranges.

HTML

<select name="PriceMin">
                <option value="min(900)">900</option>   
                <option value="min(1000)">1000</option>
                <option value="min(2000)">2000</option>   
                <option value="min(3000)">3000</option>  
                <option value="min(4000)">4000</option> 
                <option value="min(5000)">5000</option> 
                <option value="min(6000)">6000</option> 
                <option value="min(7000)">7000</option>   
                <option value="min(8000)">8000</option>           
            </select>

            <select name="PriceMax">
                <option value="min(1000)">1000</option> 
                <option value="min(2000)">2000</option>
                <option value="min(3000)">3000</option>   
                <option value="min(4000)">4000</option>  
                <option value="min(5000)">5000</option> 
                <option value="min(6000)">6000</option> 
                <option value="min(7000)">7000</option> 
                <option value="min(8000)">8000</option>   
                <option value="min(9000)">9000</option>           
            </select>

PHP

<?php
////////////connect with database goes here////////


///////////set search variables
$property = $_POST['property'];
$bedroom = $_POST['BedroomNumber'];
$bathroom = $_POST['BathroomNumber'];
$priceMin = $_POST['PriceMin'];
$priceMax = $_POST['PriceMax'];

//////////search
$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '%priceMin%' and '%priceMax%'");

if($sql === FALSE) {
    die(mysql_error()); // TODO: better error handling
}

/////////display search results
while ($row = $sql->fetch_array(MYSQLI_ASSOC)){
    echo 'ID: '.$row['Property'];
    echo '<br/> Address: '.$row['StreetAddress'];
    echo '<br/> City: '.$row['City'];
    echo '<br/> Phone: '.$row['Phone'];
    echo '<br/> Bedroom: '.$row['NumBed'];
    echo '<br/> Bathroom: '.$row['NumBath'];
    echo '<br/><img src="images/'.$row['imageName1'].'" width="200" height="150" alt=""/>';
    }

?>

Thanks

Change this:-

$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '%priceMin%' and '%priceMax%'");

to

$sql = $mysqli->query("select * from propertyinfo where Property like '%$property%' and NumBed like '%$bedroom%' and NumBath like '%$bathroom%' and Price between '$priceMin' and '$priceMax'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM