database - PHP echo issues -
this question exact duplicate of:
<?php if (!isset($_post['submit'])) $thename = $_post['thename']; $host = "localhost"; $user = "root"; $pass = ""; $db = "onlinebookclub"; $link = mysqli_connect($host, $user, $pass, $db); $query = "select * author name = '{$thename}'"; //3.excute sql query $result = mysqli_query($link, $query) or die('error querying database'); ?> <html> <head> <hr> <title></title> </head> <body> <?php if (!empty($row)) { while ($row = mysqli_fetch_array($result)) { $author_id = $row['author_id']; $name = $row['name']; $gender = $row['gender']; $birth_year = $row['birth_year']; $introduction = $row['introduction']; ?> <table> <tr> <td>name: </td> <td> <?php echo $name; ?><br/></td> </tr> <tr> <td>author id: </td> <td><?php echo $author_id; ?><br></td> </tr> <tr> <td>gender: </td> <td><?php echo $gender; ?><br/></td> </tr> <tr> <td>birth year: </td> <td><?php echo $birth_year; ?><br></td> </tr> <tr><td><hr/></td> <td><hr/></td> </tr> </table> <?php } }else { echo "no records found"; } ?> </body> </html>
i unable echo out desired results code. keeps on telling me no record found. can me error or guide me on how correct it? appreciate lot last thing finish before system can work perfectly!
instead of if (!empty($row)) { ...
if(mysqli_num_rows($result)){ ...
.
here's reference:
so code should this:
// code if(mysqli_num_rows($result)){ while ($row = mysqli_fetch_array($result)){ // code } }else { echo "no records found"; } // code
Comments
Post a Comment