Yes - sorry about that - I thought you might throw a few things at me. This syntax comes from the book PHP and MySQL Web Development so it is correct I assume.
Yes I can connect using phpmyadmin and it seems to be working and I am using the test database which is what was replaced in this syntax.
<html><head> <title>Book-O-Rama Search Results</title></head><body><h1>Book-O-Rama Search Results</h1><? 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", "test", "test");
if (!$db) {
echo "Error: Could not connect to database. Please try again later.";
exit;
}
mysql_select_db("books");
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$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 stripslashes($row["title"]);
echo "</strong><br>Author: ";
echo stripslashes($row["author"]);
echo "<br>ISBN: ";
echo stripslashes($row["isbn"]);
echo "<br>Price: ";
echo stripslashes($row["price"]);
echo "</p>";
}
?>
</body>
</html>
Every time I run this script I get the error returned "Error: Could not connect to database. Please try again later."
Any ideas?
Thanks again,
Larry