PHP Error while querying database data
The following error occurred when PHP queried the books table in database books!
Notice:trying to get property of Non-object in D:\wamp\Apache\htdocs\php\results.php on line 33
Fatal Error:call to a member function Fetch_assoc () on a non-object in D:\wamp\Apache\htdocs\php\results.php on line 35
The code is as follows:
PHP Code
<title>Book-o-rama Catalog Search</title> Book-o-rama Catalog Search
Query ($sql); $num _result= $result->num_rows; for ($i =0; $i <= $num _result; $i + +) {$row = $result->fetch_assoc (); echo "". ($i + 1). " Title: "; Echo Htmlspecialchars (stripslashes ($row [' author ')); echo "Author:". Stripslashes ($row->newsauthor); echo "ISBN:". Stripslashes ($row->NEWSISBN); echo "Price:". Stripslashes ($row->newsprice). "
"; }} $result->free (); $db->colse ();? >
The above problem that tiny prawn can give a solution!
------Solution--------------------
PHP code
$sql = "SELECT * from Books where". $searchtype. " Like '% '. $searchterm. " %'"; if ($result = $db->query ($sql)) {$num _result= $result->num_rows; for ($i =0; $i <= $num _result; $i + +) {$row = $result->fetch_assoc (); echo "". ( $i + 1). " Title: "; Echo Htmlspecialchars (stripslashes ($row [' author ')); echo "Author:". Stripslashes ($row->newsauthor); echo "ISBN:". Stripslashes ($row->NEWSISBN); echo "Price:". Stripslashes ($row->newsprice). "
"; }}else{echo "fail."; Exit }