Display (Read) a Simple CRUD Database App: Connecting to MySQL with PHP

Display Database Example  


<?php

error_reporting(0);
ini_set(display_errors, 1);
$servername='localhost' ; 
$database_name='crud'; 
$database_username='root';
$database_password=''; 
mysql_connect($servername,$database_username,$database_password);
mysql_select_db($database_name);


$sql = "SELECT * FROM `myschool` ORDER BY `myschool`.`stid` ASC ";
$run_qry = mysql_query($sql);
$my_row = mysql_fetch_array($run_qry);
//(`stid`, `fname`, `lname`, `password`, `birthdate`)
?>
<div class="container">
  <a href="create.php" >create</a>
<table class="table table-bordered">
  <thead>
    <tr>
      <th scope="col">#</th>
      <th scope="col">First Name</th>
      <th scope="col">Last Name</th>
      <th scope="col">Password</th>
      <th scope="col">Birth Date</th>
      <th scope="col">Tools</th>
    </tr>
  </thead>
  <tbody>
    <?php
while($my_row = mysql_fetch_array($run_qry) )
{
  ?>
 
 
    <tr>
      <td><?php echo $my_row['stid'];?></td>
      <td><?php echo $my_row['fname'];?></td>
      <td><?php echo $my_row['lname'];?></td>
      <td><?php echo $my_row['password'];?></td>
      <td><?php echo $my_row['birthdate'];?></td>
      <td>
      <a href="delete.php?stid=<?php echo $my_row['stid'] ;?>" >delete</a>
      <a href="update.php?stid=<?php echo $my_row['stid'] ;?>" >Update</a>
      </td>

    </tr>
<?php
$num++;
}
?>
  </tbody>
</table>
</div>

No comments

Note: only a member of this blog may post a comment.