Exception occurred when PHP queried database data

Source: Internet
Author: User
Tags php error
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 }
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.