What should I do if I cannot query the connection to mysql?

Source: Internet
Author: User
Why can't I query a single page of the table after I connect to mysql? PHPcode & lt; html & gt; & lt; head & gt; catalogsearch & lt; head & gt; & lt; body & gt; & lt; h1 & gt; catalogsearch & lt; h1 & gt; & lt; formaction & quot; results. why does php & quot; metho fail to query mysql connection?
Code for a single table page:
PHP code
  catalog searchcatalog 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 can't the query result be found?

------ Solution --------------------
You have not performed an 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. "% '";
A space is missing before like in
Is writing like this refreshing?
$ Query = "select * from books where $ searchtype like '% $ searchterm % '";


------ Solution --------------------
$ Query = "select * from books where". $ searchtype. "like '%". $ searchterm. "% '";
Echo $ query; then you will know whether it is equivalent. Is it true that the red part is connected together?
------ Solution --------------------
$ Query = "select * from books where". $ searchtype. "like '%". $ searchterm. "% '";
$ Query = "select * from books where $ searchtype like '% $ searchterm % '";
These two sqls are different.
"" Contains strings, and you can directly write. $ searchtype without spaces .... Do you think the results are the same?

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.