I have an HTML form and a results.php page.
It keeps telling me there is an error on line 29. Can anyone see what is wrong with it?
Warning: Supplied argument is not a valid MySQL result resource in /opt/apache/htdocs/client_results.php on line 29
Number of entries found:
The HTML form is first:
<head>
<title>4i dotCom Client Search</title>
</head>
<body>
<h1>Client Search</h1>
<form action="http://localhost/client_results.php" method="post">
Choose Search Type:<br>
<select name="searchtype">
<option value="Industry">Industry
<option value="ClientName">Name
<option value="ClientPostCode">Post Code
<option value="ClientStName">Street
</select>
<br>
Enter Search Text:<br>
<input name="searchterm" type=text>
<br>
<input type=submit value="Search">
</form>
</body>
Here is the results.php page:
<head>
<title>4i dotCom Client Search</title>
</head>
<body>
<h1>4i dotCom Client Search</h1>
<?
trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "You have not entered search details. Please go back and try again.";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
$db = @mysql_pconnect("localhost.localdomain:3306","root","password");
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("4i_dotCom");
$query = "select * from 4i_dotCom where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of entries found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<p><strong>".($i+1).". Industry: ";
echo htmlspecialchars( stripslashes($row["Industry"]));
echo "</strong><br>Name: ";
echo htmlspecialchars( stripslashes($row["ClientName"]));
echo "<br>Post Code: ";
echo htmlspecialchars( stripslashes($row["ClientPostCode"]));
echo "<br>Street: ";
echo htmlspecialchars( stripslashes($row["ClientStreetName"]));
echo "</p>";
}
?>
</body>
Thanks anyone!!