Hello guys i need some help with this code.
I have to build a simple bookstore ( for a university class ) but i stuck in here for many hours... The code is similar to a code from a book but still doesn't work...
The error says:
Fatal error: Call to undefined function query() in C:\Program Files\EasyPHP
2.0b1\www\eshop\results.php on line 32
So line 32 is part of this code:
@ $db = mysql('localhost','eshop');
if (mysqli_connect_errno())
{
echo "Error:No Access to Database. Try again later.";
exit;
}
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
Please help!
The complete code is and i call this php document from a html form etc:
<html>
<head>Roads Bookstore</head>
<title>Roads Bookstore</head>
<body>
<h1>Roads E-search Results</h1>
<?php
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm=trim($searchterm);
if (!$searchtype || !$searchterm)
{
echo "Not Enough Details. Please Try again.";
exit;
}
if (!get_magic_quotes_gpc())
{
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = mysql('localhost','eshop');
if (mysqli_connect_errno())
{
echo "Error:No Access to Database. Try again later.";
exit;
}
$query = "select * from books where ".$searchtype." like '%".$searchterm."%'";
$result = $db->query($query);
$num_results = $result->num_rows;
echo "<p>Number of items found: ".$num_results."</p>";
for ($i=0; $i < $searchresults; $i++)
{
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1)."Title: ";
echo htmlspecialchars(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>";
}
$result->free();
$db->close();
?>
</body>
</html>