Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. <?php
  2. $conn = new mysqli('localhost','root','','sample_db');
  3. if ($conn->connect_error) {
  4. die("Connection failed:".$conn->mysqli_error);
  5. }
  6. if(isset($_POST['username'])){
  7. $uname= $_POST['username'];
  8. $pass= $_POST['password'];
  9. $type= $_POST['type'];
  10.  
  11. $str = "INSERT INTO tbl_users(username,password,type) VALUES('".$uname."','".$pass."','".$type."')";
  12. if ($conn->query($str)===TRUE) {
  13. echo "NEW data added";
  14. }else{
  15. echo "Error:".$conn->connect_error;
  16. }
  17. }
  18. ?>
  19. <!DOCTYPE html>
  20. <html>
  21. <head>
  22. <title></title>
  23. </head>
  24. <body>
  25. <form method="POST">
  26. Username: <input type="text" name="username"><br>
  27. Password: <input type="password" name="password"><br>
  28. Type: <input type="text" name="type"><br>
  29. <button>SUBMIT</button><br>
  30.  
  31. </form>
  32. <form method="POST">
  33. Delete: <input type="number" name="delete">
  34. <button>DELETE</button>
  35. </form>
  36. <?php
  37. $del= $_POST['delete'];
  38.  
  39. $sql = "DELETE FROM tbl_users WHERE id='$del'";
  40.  
  41. if ($conn->query($sql) === TRUE) {
  42. echo "Record deleted successfully";
  43. } else {
  44. echo "Error deleting record: " . $conn->error;
  45. }
  46. $str= "SELECT * FROM tbl_users";
  47. $result = $conn->query($str);
  48. echo "<table border=1>";
  49. if ($result->num_rows>0) {
  50. while($row=$result->fetch_assoc()){
  51. echo "<tr><td><a href='https://www.google.com/webhp?hl=en&ictx=2&sa=X&ved=0ahUKEwj_rqT6i6LlAhXZc94KHZV4DhYQPQgH?id="
  52. .$row['id']."'>"
  53.  
  54. .$row['id']."</a></td><td>"
  55. .$row['username']."</td><td>"
  56. .$row['password']."</td><td>"
  57. .$row['type']."</td></tr>";
  58. }
  59. }
  60. echo "</table>";
  61. $conn->close();
  62. ?>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement