I keep getting a warning on my server after trying to do a search it says:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given inform/search.php on line 19
Heres the code, I don't quite understand why its not displaying the result. Any help would be much appreciated.
<?php
if(isset($_POST['submit'])){
if(isset($_GET['go'])){
if(preg_match("/^[ a-zA-Z]+/", $_POST['postcode'])){
$postcode=$_POST['postcode'];
//connect to the database
}
$con = mysql_connect('*****','*****','*****'); //connect to the database
if (!$con) //if cannot connect to the database, terminate the process
{
die('Could not connect: ' . mysql_error());
}
$mydb=mysql_select_db("dataproj");
//-query the database table
$sql="SELECT * FROM companies WHERE postcode LIKE '%" . $postcode ."%'";
//-run the query against the mysql query function
$result=mysql_query($sql);
//-create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$postcode =$row['postcode'];
$cname=$row['cname'];
//-display the result of the array
echo "<ul>\n";
echo "<li>" . $postcode . " " . $cname . "</a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
?>