I have spent couple of weeks trying to solve the following problem to no avail.
When I enter and execute a search through my form, no result is displayed in the table and the following symbols appears above the table: " }?>
The script for the form is as follows:
<form method="post" action="searchform_results1.php">
<div align="center">
<table border="0" cellpadding="1" cellspacing="1" align="centre">
<tr>
<td>
<select name="searchcategory" size="1">
<option value="firstname">First Name</option>
<option value="surname">Surname</option>
<option value="telephone_no">Telephone</option>
<option value="emailaddress">Email Address</option>
</select>
<input type="text" name="search" size="30"><br></p>
Search database:<input type="submit" Name="submit" value="Sumbmit" size="20">
</td>
</tr>
</table>
</div>
</form>
I use the following script to process the query result:
<?php
MYSQL_CONNECT("localhost","twilson","marquis") OR DIE("Database connection unavailable");
mysql_select_db("general") or die("Unable to connect to the database");
//query the table
$query = mysql_query("SELECT * FROM contact_details WHERE $searchcategory LIKE '%$search%' LIMIT 0, 10"));
$num=mysql_num_rows($result);
if (mysql_num_rows($query) ==0)
{
echo "no record match your criteria";}
?>
<h1 align="center">Search Report</H1>
<TABLE align=center cellpaddig=2 border=1>
<TR>
<TH>First Name</TH>
<TH>Surname</TH>
<TH>Telephone No.</TH>
<TH>Email Address</TH>
</tr>
<?php
while ($row = mysql_fetch_array($query))
{
$firstname=$row["firstname"];
$surname=$row["surname"];
$telephone_no=$row["telephone_no"];
$emailaddress=$row["emailaddress"];
//Display results
echo
"<TR>
<TD>$row[firstname]</TD>
<TD>$row[surname]</TD>
<TD>$row[telephone_no]</TD>
<TD>$row[emailaddress]</TD>
</TR>"
}
?>
</table>
</BODY>
</HTML>
I would be grateful if anyone can advice/assist me to resolve the problem.
Thanks