I'm going through the process of trying to teach myself php and mysql. I'm working from a book and I've come accross a problem. It's a basic search function on a web page. The code on search.php page where the user would select the criteria of the search goes like this:
<body>
<h1>Book-O-Rama Catalog Search</h1>
<form action="results.php" method="post">
Choose Search Type:<br>
<select name="searchtype">
<option value="author">Author<option value="title">Title
<option value="isbn">ISBN
</select>
<br>
Enter Search Term:<br>
<input name="searchitem" type=text>
<br>
<input type=submit value="Search">
</form>
and the code on my results.php page looks like this:
<h1>Book-O-Rama Search Results</h1>
<?php
trim($searchitem);
if (!searchtype || !$searchitem)
{
echo "You have not entered Search details. Please go back and try again";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "dbname", "dbname");
if (!$db)
{
echo "Error. Could not Connect to database. Please try again";
exit;
}
mysql_select_db("books");
$query = "select * from books where ".$searchtype." like'%".$searchterm."%'";
$result = mysql_num_row($query);
$num_results = mysql_num_rows($result);
echo "<p>Number of books found: ".$num_result."</p>";
for ($i=0; $i <$numresults; $i++)
{
$row = mysql_fetch_array($result);
echo"<p><strong>".($i+1).". Title: ";
echo htmlspecialchars( stripslashes($row["title"]));
echo "<strong><br>Author: ";
echo htmlspecialchars (stripeslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars (stripeslashes($row["isbn"]));
echo "<br>Price: ";
echo htmlspecialchars (stripeslashes($row["price"]));
echo "</p>";
?>
Now... The problem is When i click search it comes up with an error message on results page saying:
Parse error: parse error in c:\phpdev\www\tests\results.php on line 46
the only code on Line 46 of my code </html>, the end of the document.
Any Help would be much appreciated
Thankyou
Robert