I cannot figure out this error.
When I run the following code, it continually does the first if statement that states that $citySelect is blank (or equal to spaces, meaning all ads will display), when infact I select a city from the first selection form, meaning that $citySelect should NOT be equal to spaces (and only the ads with the selected city should display). If anyone could help me with this problem, I would really appreciate it. I will continue to debugg it, but it has really given me fits. The "include get_results" line simply is a script that displays the query results.
Thanks, Adam V.
----code----
<?
include("header.php");
?>
<div id="content">
<?
include("sub_menu.php");
?>
<table><tr><td><h1>Search Rentals</h1></td></tr></table>
<?
if(isset($_POST['searchform'])){
switch($type)
{
case 'ta' :
$rental_type = "";
break;
case 'tb' :
$rental_type = 'apartment';
break;
case 'tc' :
$rental_type = 'house';
break;
case 'td' :
$rental_type = 'studio';
break;
default :
die("selection error- Please try again");
break;
}
switch($rent)
{
case 'ra' :
$rental_low = 0;
$rental_high = 0;
break;
case 'rb' :
$rental_low = 100;
$rental_high = 300;
break;
case 'rc' :
$rental_low = 300;
$rental_high = 500;
break;
case 'rd' :
$rental_low = 500;
$rental_high = 700;
break;
case 're' :
$rental_low = 700;
$rental_high = 900;
break;
case 'rf' :
$rental_low = 900;
$rental_high = 90000;
break;
default :
die("selection error- Please try again");
break;
}
switch($bedrooms)
{
case 'ba' :
$bed = 0;
break;
case 'bb' :
$bed = 1;
break;
case 'bc' :
$bed = 2;
break;
case 'bd' :
$bed = 3;
break;
case 'be' :
$bed = 4;
break;
case 'bf' :
$bed = 5;
break;
case 'bg' :
$bed = 6;
break;
case 'bh' :
$bed = 7;
break;
default :
die("selection error- Please try again");
break;
}
switch($bathrooms)
{
case 'aa' :
$bath = 0;
break;
case 'ab' :
$bath = 1;
break;
case 'ac' :
$bath = 2;
break;
case 'ad' :
$bath = 3;
break;
case 'ae' :
$bath = 4;
break;
case 'af' :
$bath = 5;
break;
case 'ag' :
$bath = 6;
break;
case 'ah' :
$bath = 7;
break;
default :
die("selection error- Please try again");
break;
}
/*************************************************************************************/
/ Section where we try all possible search selections and the query the database /
/*************************************************************************************/
/ if all search fields are blank, including city: /
if($bath == 0 && $bed == 0 && $rental_low == 0 && $rental_high == 0 && $rental_type == "" && $citySelect == ""){
$result = mysql_query( "SELECT * FROM property_info order by property_id")
or die("SELECT Error: ".mysql_error());
echo "select 1";
include("get_results.php");
}
/ if all search fields are blank, except city: /
elseif($bath == 0 && $bed == 0 && $rental_low == 0 && $rental_high == 0 && $rental_type == "" && $citySelect != ""){
$result = mysql_query( "SELECT * FROM property_info WHERE cty = '$citySelect' order by property_id")
or die("SELECT Error: ".mysql_error());
echo "select 2";
include("get_results.php");
}
/*************************************************************************************/
/ end selection process /
/*************************************************************************************/
echo "</div>";
include("footer.php");
die("");
}
if(isset($_POST['citySubmit'])){
switch($city)
{
case 'a' :
$citySelect = "";
break;
case 'b' :
$citySelect = 'Ada';
break;
case 'c' :
$citySelect = 'Bellefountaine';
break;
case 'd' :
$citySelect = 'Kenton';
break;
case 'e' :
$citySelect = 'Lima';
break;
case 'f' :
$citySelect = 'Findlay';
break;
case 'g' :
$citySelect = 'Marion';
break;
case 'h' :
$citySelect = 'Upper Sandusky';
break;
default :
die("selection error- Please try again");
break;
}
?>
<form action = "<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>" method="post">
<table>
<tr><td>Rental type:</td><td>
<select name ="type">
<option value = "ta">search all
<option value = "tb">Apartment
<option value = "tc">House
<option value = "td">Studio
</select>
</td></tr>
<tr><td>Rent amount:</td><td>
<select name ="rent">
<option value = "ra">search all
<option value = "rb">$100-$300
<option value = "rc">$300-$500
<option value = "rd">$500-$700
<option value = "re">$700-$900
<option value = "rf">$900 and above
</select>
</td></tr>
<tr><td>No. of bedrooms:</td><td>
<select name ="bedrooms">
<option value = "ba">search all
<option value = "bb">1
<option value = "bc">2
<option value = "bd">3
<option value = "be">4
<option value = "bf">5
<option value = "bg">6
<option value = "bh">7 and above
</select>
</td></tr>
<tr><td>No. of bathrooms:</td><td>
<select name ="bathrooms">
<option value = "aa">search all
<option value = "ab">1
<option value = "ac">2
<option value = "ad">3
<option value = "ae">4
<option value = "af">5
<option value = "ag">6
<option value = "ah">7 and above
</select>
</td></tr>
<TR><td colspan="2"><BR> <input type="submit" name="searchform" value="Search"> </td></tr>
</table></form><BR><BR><BR><BR><BR><BR><BR><BR></div>
<?
include("footer.php");
die("");
}
?>
<p><center><table><tr><td><font size="2" style="Trebuchet MS">Please choose a city to search. Choose "search all" to search all areas.</font></td></tr></table><BR><BR>
<form method="post" action = "<? echo $HTTP_SERVER_VARS['PHP_SELF']; ?>">
<table><tr><td>
<select name = "city">
<option value = "a">search all
<option value = "b">Ada
<option value = "c">Bellefoutaine
<option value = "d">Kenton
<option value = "e">Lima
<option value = "f">Findlay
<option value = "g">Marion
<option value = "h">Upper Sandusky
</select></td>
<td>
<input type="submit" name="citySubmit" value="Select"></td></tr></table></form>
<table width='550' height='80' border='1' cellpadding='20'><tr bgcolor='#EDEAEB'><td>
<p align="justify">If you are a landlord or property manager, and have not yet registered an account with us, what are you waiting for? By registering an account with wcorentals.com, you can post housing ads and instantly make them available to hundreds, even thousands of possible tenants. <font color="red">Registering is free, and due to wcorentals.com being a brand new company, we are allowing landlords to post ads for FREE the first six months of our existance.</font><BR><BR>Posting ads is currently free, so click <a href="register.php">here to register</a> and post your ad today! Give us a chance, and we guarantee you won't be disappointed.</p>
</td></tr></table></center>
</center>
<BR></p>
</div>
<?
include("footer.php");
?>
</body>
</html>