html - PHP not returning mysql results -
i brand new php, or database programming in general. project have query bookstore database book info (a small database) , display on following page. below code bookstore search page:
<?php $con = mysqli_connect("localhost", "root", "root") or die("error connecting database: ".mysqli_error()); mysqli_select_db($con, "bookstore") or die(mysqli_error()); ?> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>book store</title> </head> <body> <td><h1>book search</h1> </td> <table width="100%" border="0"> <tr> <form method="post" action="search.php?go" id="searchform"> <input type="text" name="name"> <input type="submit" name="submit" value="search title"> </form> <form method="post" action="search.php?go" id="searchform"> <input type="text" name="category"> <input type="submit" name="submit" value="search category"> </form> </tr> </table> </body> </html>
and following simple search.php code query's database , returns results. unable see results. thing shows "book title search results" nothing below. means problem in while loop.
<?php $con = mysqli_connect("localhost", "root", "root") or die("error connecting database: ".mysqli_error()); mysqli_select_db($con, "bookstore") or die(mysqli_error()); ?> <!doctype html> <html> <head> <title>search results</title> <meta http-equic="content-type" content="text/html; charset=utf-8" /> </head> <body> <?php if (isset($_post['name'])){ $query = $_post['name']; $sql = mysqli_query($con, "select * books (`title` '%".$query."%')") or die(mysqli_error($con)); if (mysqli_num_rows($sql) > 0) { echo "</br> book title search results </br>"; while ($row = mysqli_fetch_array($sql, mysql_assoc)) { echo "</br>title: " .$row['title']. ", author: " .$row['author'].", year: " .$row['year'] . ", price: $" .$row['price'] ."</br>"; echo '<img src="data:image/jpeg;base64,'.base64_encode( $row['cover'] ).'"/>'; } }else{ // if there no matching rows following echo "no results"; } } ?> </body> </html>
i have 6 columns in database: title
, author
, year
, price
, category
, image
(blob file), , have checked naming in query functions cannot figure out. can push me in right direction or show me i'm doing wrong? i'm using mamp web server.
there typo in code. use mysqli_assoc
instead of mysql_assoc
. rest of code correct.
Comments
Post a Comment