Why MySQL is connected and can't be queried
Form page code:
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 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?