php - Populating HTML Table with Data from mysql Gives Empty Table Cells -


i want populate table data mysql database php, table cells remain empty when code executed, , don't receive errors

below code:

<?php $host = "localhost"; // host name  $username = ""; // mysql username  $password = ""; // mysql password  $db_name = "test"; // database name  $tbl_name = "test_mysql"; // table name  $server_name = "localhost";  // create connection $con = new mysqli($server_name, $username, $password, $db_name, 3306); if($con->connect_error){     die("connection failed: ".$con->connect_error); }  // check connection if($con->connect_error){     die("connection failed: ".$conn->connect_error); }  $sql = "select * $tbl_name"; $result = $con->query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0">     <tr>         <td>             <table width="400" border="1" cellspacing="0" cellpadding="3">                 <tr>                     <td colspan="4"><strong>list data mysql</strong></td>                 </tr>                 <tr>                     <td align="center"><strong>name</strong></td>                     <td align="center"><strong>lastname</strong></td>                     <td align="center"><strong>email</strong></td>                     <td align="center"><strong>update</strong></td>                 </tr>                 <?php                 if($result->num_rows > 0){                     // output data of each row                     while($row = $result->fetch_assoc()){ ?>                         <tr>                             <td><? echo $rows['name']; ?></td>                             <td><? echo $rows['lastname']; ?></td>                             <td><? echo $rows['email']; ?></td>                             <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>                         </tr>                         <?php                     }                 }                 ?>             </table>         </td>     </tr> </table> <?php $con->close(); ?> 

i think missing code, appreciate can give me!

try this...

<?php $host = "localhost"; // host name  $username = ""; // mysql username  $password = ""; // mysql password  $db_name = "test"; // database name  $tbl_name = "test_mysql"; // table name  $server_name = "localhost";  // create connection $con = new mysqli($server_name, $username, $password, $db_name, 3306); if($con->connect_error){    die("connection failed: ".$con->connect_error); }  // check connection if($con->connect_error){  die("connection failed: ".$conn->connect_error); }  $sql = "select * $tbl_name"; $result = $con->query($sql); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr>     <td>         <table width="400" border="1" cellspacing="0" cellpadding="3">             <tr>                 <td colspan="4"><strong>list data mysql</strong></td>             </tr>             <tr>                 <td align="center"><strong>name</strong></td>                 <td align="center"><strong>lastname</strong></td>                 <td align="center"><strong>email</strong></td>                 <td align="center"><strong>update</strong></td>             </tr>             <?php             if($result->num_rows > 0){                 // output data of each row                 while($rows = $result->fetch_assoc()){ ?>                     <tr>                         <td><?php echo $rows['name']; ?></td>                         <td><?php echo $rows['lastname']; ?></td>                         <td><?php echo $rows['email']; ?></td>                         <td align="center"><a href="update.php?id=<?php echo $rows['id']; ?>">update</a></td>                     </tr>                     <?php                 }             }             ?>         </table>     </td> </tr> </table> <?php $con->close(); ?> 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -