Good Day.
I've been trying to sucessfully run a simple PHP script, but have
failed. It is what others call a simple code. How would I query
a mySql database and display the results back to the user? This is the code I'm using.
<?
trim($searchterm);
if(!$searchtype || !searchterm)
{
echo "You have not entered the required information!";
exit;
}
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
@ $db = mysql_pconnect("localhost", "userID", "pwd");
if(!$db)
{
echo "Error: Could not connect to database.";
exit;
}
mysql_select_db("books");
$query = "select * from books";
$result = mysql_query($query);
$num_results = mysql_num_rows($result)
echo "<p>Number of books found: ".$num_results."</p>";
for($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo "<P><strong>".($i+1).". Title: ";
echo htmlspecialchars( stripslashes($row["title"]));
echo "</strong><br>Author: ";
echo htmlspecialchars( stripslashes($row["author"]));
echo "<br>ISBN: ";
echo htmlspecialchars( stripslashes($row["isbn"]));
echo "<br>Price: ";
echo htmlspecialchars( stripslashes($row["price"]));
echo "</P>";
}
?>
I usually get the error msg's:
Parse error: parse error, unexpected T_ECHO
or
T_FOR
Can someone guide me down the right path with the correct
way of doing this?
Thanks...