Advertisement
Guest User

Untitled

a guest
May 19th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. <html>
  2. <head>
  3. <basefont face="Arial">
  4. </head>
  5. <body>
  6.  
  7.  
  8. <?php
  9. $host = "localhost";
  10. $user = "root";
  11. $pass = "akecbdy6";
  12. $db = "passwd";
  13. $table = "details";
  14.  
  15. // create mysql object
  16. // open connection
  17. $mysqli = new mysqli($host, $user, $pass, $db);
  18.  
  19. // check for connection errors
  20. if (mysqli_connect_errno()) {
  21. die("unable to connect");
  22. }
  23.  
  24. // if id is provided, then delete that record
  25. if (isset($_GET['id'])) {
  26. // create query to delete record
  27. $query = "DELETE FROM $table WHERE id = ".$_GET['id'];
  28.  
  29. // execute query
  30. if ($mysqli->query($query)) {
  31. // print number of affected
  32. echo $mysqli->affected_rows." row(s) affected";
  33. }
  34. else {
  35. // print error message
  36. echo "Error in query: $query. ".$mysqli->error;
  37. }
  38. }
  39.  
  40. $query = "SELECT * FROM $table";
  41.  
  42. // execute query
  43. if ($result = $mysqli->query($query)) {
  44. // see if any rows were returned
  45. if ($result->num_rows > 0) {
  46. // yes
  47. // print them one after another
  48. echo "<table cellpadding=10 border=1>";
  49. while($row = $result->fetch_array()) {
  50. echo "<tr>";
  51. echo "<td>".$row[0]."</td>";
  52. echo "<td>".$row[1]."</td>";
  53. echo "<td>".$row[2]."</td>";
  54. echo "<td><a href=".$_SERVER['PHP_SELF']."?id=".$row[0].">Delete User</a></td>";
  55. echo "</tr>";
  56. }
  57. }
  58.  
  59. // free result set memory
  60. $result->close();
  61. }
  62.  
  63. else {
  64. // print error message
  65. echo "Error in query: $query. ".$mysqli->error;
  66. }
  67.  
  68. $mysqli->close();
  69. ?>
  70.  
  71. </body>
  72. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement