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?