I'm trying to search a mysql table column for a number. However when I enter a number into the search form I get told that no query has been entered.
Here is my code. Database connection information left out on purpose.
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['search'])){
$search=$_POST['search'];
$db=mysql_connect ("", "", "") or die ('I cannot connect to the database because: ' . mysql_error());
$mydb=mysql_select_db("");
$sql="SELECT CompanyID, ZipCat FROM A WHERE ZipCat LIKE '%" . $search . "%'";
$result=mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Company ID</th>
<th>ZipCat</th>
</tr>";
while($row=mysql_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['CompanyID'] . "</td>";
echo "<td>" . $row['ZipCat'] . "</td>";
echo "</tr>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
?>
I can search for a name or a word. Probably an easy fix but I cannot figure it out for the life of me. Any help would be apreciated.