The_FedEx_Guy wrote:
> <td><select name="minPrice" id="minPrice">
> <option value="Any">Any</option>
> <option
value="25.000">£25.000</option>
> <option
value="50.000">£50.000</option>
>
> The Price values should be eg. ?200,000.00 But I have
not really worked on
> these. I have at the moment only used values like
?200.000 I suspect that is
> the problem with the search based on price problem
Numbers stored in a database should not contain any
punctuation other
than a decimal point. By using 25.000, you are specifying 25,
not
25,000. You are creating unnecessary difficulties for
yourself. There's
nothing wrong with displaying the figures with commas as the
thousands
separator in the drop-down menu, but leave them out in the
value like this:
<option value="25000">£25,000</option>
<option value="50000">£50,000</option>
> $sql = "SELECT * FROM property WHERE B_R = 'BUY' AND
Accepted = 'Yes' AND
> PropType = '$PropType' AND (NoBeds ='$NoBeds' or NoBeds
>'0' or '$NoBeds' ='0')
> AND (Cost >='$minPrice' AND Cost <='$maxPrice')
AND Country = 'UK'";
You have a lot of variables in there. You're also doing
nothing to
prevent SQL injection. Filter the user input like this to
build the SQL
query.
// define an array of acceptable property types
$propTypes = array('Houses', 'Flats/Apartments', 'Bunglows',
'Character Property', 'Commercial', 'Land', 'Investment
Properties');
// if submitted value is in the array of acceptable types,
use it
// otherwise, use a wildcard character
if (isset($_GET['PropType']) &&
in_array($_GET['PropType'], $propTypes)) {
$PropType = "= '".$_GET['PropType']."'";
} else {
$PropType = 'LIKE %';
}
// check that the number of bedrooms is a number
// if it's zero, search for all numbers
if (isset($_GET['NoBeds']) &&
is_numeric($_GET['NoBeds']) &&
$_GET['NoBeds'] == 0) {
$NoBeds = '> 0';
} elseif (isset($_GET['NoBeds']) &&
is_numeric($_GET['NoBeds']) &&
$_GET['NoBeds'] > 0) {
$NoBeds = '= '.$_GET['NoBeds'];
} else {
$NoBeds = '> 0';
}
// if minPrice is not a number, set it to zero
// otherwise, use the submitted value
if (isset($_GET['minPrice']) &&
!is_numeric($_GET['minPrice']) ||
!isset($_GET['minPrice'])) {
$minPrice = 0;
} elseif (isset($_GET['minPrice']) &&
is_numeric($_GET['minPrice'])) {
$minPrice = $_GET['minPrice'];
}
// if maxPrice is not a number, set it to 100 million
// otherwise, use the submitted value
if (isset($_GET['maxPrice']) &&
!is_numeric($_GET['maxPrice']) ||
!isset($_GET['maxPrice'])) {
$minPrice = 100000000;
} elseif (isset($_GET['maxPrice']) &&
is_numeric($_GET['maxPrice'])) {
$minPrice = $_GET['maxPrice'];
}
$sql = "SELECT * FROM property WHERE B_R = 'BUY' AND Accepted
= 'Yes'
AND PropType $PropType AND NoBeds $NoBeds AND Country = 'UK'
AND Cost BETWEEN $minPrice AND $maxPrice";
--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of
ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/