I am developing a real estate script. The script has a search option where an user can specify the price range eg. user_price_low to user_price_high and the listings have to be fetched from a database, which has eg. db_price_high and db_price_low.
I used a BETWEEN statement trying to find the matches,
WHERE price_low BETWEEN '.$_REQUEST['minprice_buy'].' AND '.$_REQUEST['maxprice_buy']
but to my surprise…
If an user has user_price_high = 60 and user_price_low = 20
AND
the record has db_price_low = 30 and db_price_high = 120
my query is invalid in this case.
i tried looking at MySql Query- Date Range within a Date Range but does that match what I want?
Chandan, never ever input $_* functions directly into a query. It’s an SQL-injection hole.
Change the code to:
With regards to your question, change the query to something like:
You may also want to consider:
Here
min_priceandmax_pricedon’t need to both be in the range at all times.See: How does the SQL injection from the "Bobby Tables" XKCD comic work?