Why the connection to MySQL but can not query, how to deal with

Source: Internet
Author: User
Why MySQL is connected and can't be queried
Form page code:
PHP Code
  
   Catalog Search

Catalog Search



PHP Code
  

Search results

Query ($query); $num _results= $result->num_rows;echo "

Number of books found: ". $num _results."

for ($i =0; $i < $num _results; $i + +) {$row = $result->fetch_assoc (); Echo

". ($i + 1). " Title: "; Echo Htmlspecialchars (stripslashes ($row [' title ']); echo "
Author: "; Echo stripslashes ($row [' author ']); Echo
ISBN: "; Echo stripslashes ($row [' ISBN ']); Echo
Price: "; Echo stripslashes ($row [' Price ']); Echo

";}? >


Output Result:

Search results
Number of books found:

Why does the query not result

------Solution--------------------
You do not check the error after executing the query, you should make up
1. Confirm that $searchtype is the correct field name
2. $query = "SELECT * from Books where". $searchtype. " Like '% '. $searchterm. " %'";
There's a space missing before the like.
Isn't it refreshing to write like this?
$query = "SELECT * from books where $searchtype like '% $searchterm% '";


------Solution--------------------
$query = "SELECT * from Books where". $searchtype. " Like '% '. $searchterm. " %'";
Echo $query, and know if it's equivalent. The Scarlet Letter part is connected, right?
------Solution--------------------
$query = "SELECT * from Books where". $searchtype. " Like '% '. $searchterm. " %'";
$query = "SELECT * from books where $searchtype like '% $searchterm% '";
There is a difference between these two SQL.
"" All of them are strings, and then you have no spaces to write directly. $searchtype .... Do you think about the results yourself?
  • 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.