I have created a form, with two input boxes one for city one for zip code, I would like to be able to search using either the city or the zip code. but only the city works. I can comment out the city code and the zip code input works. Would you folks please take a look at this and let me know what I am doing wrong.
Thank you.
<!-- Start of FORM -->
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
<!-- End of FORM -->
<table border="3" width="100%">
<tr><!-- Row 1 -->
<td>City</td><!-- Col 2 -->
<td><input type="text" name="city" value=""></td><!-- Col 3 -->
</tr>
<tr><!-- Row 1 -->
<td>Zip Code</td><!-- Col 2 -->
<td><input type="text" name="zip" value=""></td><!-- Col 3 -->
</tr>
<tr><!-- Row 1 -->
<td><input type="submit"name="submit"></td><!-- Col 2 -->
</tr>
</table>
</form>
<table border="2">
<tr>
<?php
$city=$_POST['city'];
$zip=$_POST['zip'];
if (isset($_POST['submit'])){
if ($city != ''){
$search ="SELECT * FROM `contacts` WHERE `city` LIKE '$city' ";
$result = @mysql_query($search);
$num_rows = mysql_num_rows($result);
echo $num_rows." ".$search;
while ($row = mysql_fetch_array($result,MYSQL_NUM)){echo "<td >".$row[0]."</td> "."<td>".$row[1]."</td> "."<td>".$row[2]."</td> "."<td>".$row[3]."</td> "."<td>".$row[4]."</td> "."<td>".$row[5]."</td> "."<td>".$row[6]."</td> "."<td>".$row[7]."</td> "."<td>".$row[8]."</td>"."<td >".$row[9]."</td> "."<td >".$row[10]."</td> "."<td >".$row[11]."</td> "."<br />";
echo "</tr>";
}
if ($zip != ''){
$search2 ="SELECT * FROM `contacts` WHERE `zip`like '$zip' ";
$result2 = @mysql_query($search2);
$num_rows = mysql_num_rows($result2);
echo $num_rows." ".$search2;
while ($row = mysql_fetch_array($result2,MYSQL_NUM)){echo "<td >".$row[0]."</td> "."<td>".$row[1]."</td> "."<td>".$row[2]."</td> "."<td>".$row[3]."</td> "."<td>".$row[4]."</td> "."<td>".$row[5]."</td> "."<td>".$row[6]."</td> "."<td>".$row[7]."</td> "."<td>".$row[8]."</td>"."<td >".$row[9]."</td> "."<td >".$row[10]."</td> "."<td >".$row[11]."</td> "."<br />";
echo "</tr>";
}
}
}
}
?>
</table>