I am having some problems with a page which contains 2 forms.
Form 1: a simple field that searches on an integer in a database, included in the master PHP document (and thus appears on ALL pages). Input is validated, or redirected to a page upon success.
Form 2: listingsCriteria.php - displays results of a real estate search, based on specific criteria
Here is my flow and how it's breaking:
- User selects form fields from a page previous to listingsCriteria, and hits submit (works fine)
- User arrives at listingsCriteria.php - has either found some listings, or 0 (works fine)
- User then goes to form 1 (search field) from within listingsCriteria.php, and enters in a 5-digit number.
[INDENT]a. Form1 is validated. This validates to false, as a valid number is 6 digits. An error is displayed. (this works fine)
[/INDENT]
[INDENT]b. listingsCriteria.php is meant to be re-displayed (or whatever page the user has searched from) - THIS BREAKS
[/INDENT]
In step 3 (listingsCriteria.php), I have set up something along these lines within a function (very shortened):
if(isset($_POST['submit'])) {
$_SESSION['priceMax'] = $_REQUEST['priceMax'];
$errmsg = array();
if ($_POST['priceMax'] == '' && empty($_POST['priceMax'])) {
$errmsg[] = "<li class=\"error\">Please enter a maximum price.<BR />";
} elseif (!Validate::isInteger($_POST['priceMax'])) {
$priceMax=preg_replace("/[^0-9]/", "", $_POST['priceMax']);
} elseif ($_POST['priceMax'] < $_POST['priceMin']) {
$errmsg[] = "<li class=\"error\">Maximum price must be greater than the minimum price.<br />";
} else {
$priceMax = $_POST['priceMax'];
}
} else {
$priceMax = $_SESSION['priceMax'];
}
In step 3, when I echo out the sql, $priceMax is stripped of everything but digits.
In step 4, the sql echoes out that $priceMax is NOT stripped of everything but digits.
EG, Step 3:
SELECT ListNum, Bedrooms, BathsFull, BathsPartial, Price, Area, AddressNum, AddressDirection, Street FROM listingsRES WHERE (Bedrooms >= 0 OR Bedrooms != NULL) AND BathsFull >= 0 AND Price BETWEEN 100 AND 150000
Step 4:
SELECT ListNum, Bedrooms, BathsFull, BathsPartial, Price, Area, AddressNum, AddressDirection, Street FROM listingsRES WHERE (Bedrooms >= 0 OR Bedrooms != NULL) AND BathsFull >= 0 AND Price BETWEEN 100 AND 150,000
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 '000' at line 1
What's really happening here?