MySQL Edit & Delete Live Update

In this tutorial we will create a MySQL Edit & Delete Live Update in PHP. This project is written in PHP and MySQL. Its a real-time process of adding, deleting and update the data of each users. The system connects to the database to pull the result and display the data to the page so the users will see their detail's in front of them.

Sample Code

Index.php - This file is for the display of form and UI for the users.
  1. <?php
  2. include('dbcon.php');
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <title>MySQL Edit & Delete Live Update</title>
  8. <link rel="stylesheet" type="text/css" href="style.css" />
  9. </head>
  10. <body>
  11. <center><h1 class="header-text">MySQL Edit & Delete Live Update</h1></center>
  12. <form method="post" action="add.php">
  13. <div>
  14. <label for="fname">First Name</label>
  15. <input type="text" id="fname" name="Firstname">
  16. <label for="mname">Middle Name</label>
  17. <input type="text" id="mname" name="Maiden">
  18. <label for="lname">Lastname</label>
  19. <input type="text" id="lname" name="Lastname">
  20. <label for="email">Email Address</label>
  21. <input type="text" id="email" name="Emailadd">
  22. <input type="submit" name="submit" value="ADD">
  23. </div>
  24. </form>
  25. </body>
  26. </html>
For the query of data from the database through the php form.
  1. <table>
  2. <?php
  3. $users_query=mysql_query("select * from users_name");
  4. while($user_rows=mysql_fetch_array($users_query)){
  5. ?>
  6. <tr>
  7. <th>Firstname</th>
  8. <th>Middle Name</th>
  9. <th>Lastname</th>
  10. <th>Email Address</th>
  11. <th>Update</th>
  12. </tr>
  13. <tr>
  14. <td><?php echo $user_rows['Firstname'] ; ?></td>
  15. <td><?php echo $user_rows['Maiden'] ; ?></td>
  16. <td><?php echo $user_rows['Lastname'] ; ?></td>
  17. <td><?php echo $user_rows['Emailadd'] ; ?></td>
  18. <td><a href="delete.php<?php echo '?id='.$user_rows['UserID']; ?>"><button class="button1">DELETE</button></a>&nbsp;
  19. <a href="edit.php<?php echo '?id='.$user_rows['UserID']; ?>"><button class="button2">EDIT</button></a>
  20. </td>
  21. </tr>
  22. <?php }?>
  23. </table>
resultEdit.php - This script is for the edit of the existing users by their users id.
  1. <?php
  2. if (isset($_POST['submit'])){
  3. $Firstname=$_POST['Firstname'];
  4. $Maiden=$_POST['Maiden'];
  5. $Lastname=$_POST['Lastname'];
  6. $Emailadd=$_POST['Emailadd'];
  7. mysql_query("update users_name set Firstname='$Firstname',Maiden='$Maiden',Lastname='$Lastname',Emailadd='$Emailadd' where UserID='$id'");
  8. header('location:index.php');
  9. }
  10. ?>
resultDbcon.php - Is for the connection of database.
  1. <?php
  2. @mysql_select_db('users',mysql_connect('localhost','root',''));
  3. ?>
For more programming tutorials don't forget to Like & Share for more update's. Hope that you learn from this tutorial. Enjoy Coding!

Add new comment