The following error occurs when PHP queries the books table in the database books! Notice: Tryingtogetpropertyofnon-objectinD: wampApachehtdocsphpresults. phponline33Fatalerror: Calltoamemberfunctio PHP error when querying database data
The following error occurs when PHP queries the books table in the 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
Book-O-Rama Catalog Search 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();?>
For the above problem, slight prawns can provide 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; }