Below is a form page and a result.php page.
I am getting the error:
Error: You have an error in your SQL syntax near 'Resource id #2' at line 1
When I use the MySQL monitor, it returns the correct result with:
"select * from Clients where Industry = 'Energy';
So it has to be something wrong with the syntax on the .php result page.
<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 Clients where ".$searchtype." like '%".$searchterm."%'";
$result = mysql_query($query);
$result = mysql_query($result) or die("Error: ".mysql_error());
$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>