Advertisement
HelloDearSir

aids

Mar 15th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en-GB">
  3. <head>
  4. <title>test2.php</title>
  5. <link rel="stylesheet" href="uplaod1.css">
  6. </head>
  7. <body>
  8. <div class="heading">
  9. <h2> T0 do list</h2>
  10. </div>
  11. <form method="post" action="">
  12. <?php
  13. $db = mysqli_connect("localhost", "root", "root", "todo") or die("QUERY failed". mysqli_error($db));
  14. if (isset($_POST['task'])) {
  15. $task = $_POST['task'];
  16. $query = "INSERT INTO tasks(task) VALUES('$task')";
  17.  
  18. if(!$run_query = mysqli_query($db, $query)) {
  19. printf('QUERY failed -- ' . mysqli_error($db) . '<br />');
  20. } else {
  21. printf('QUERY ok<br />');
  22. }
  23. }
  24. ?>
  25. <input type="text" name="task" class="task" />
  26. <button type="submit" class="add_btn" name="submit">Add the task</button>
  27. </form>
  28. <table>
  29. <thead>
  30. <tr>
  31. <th>N</th>
  32. <th>&nbsp;</th>
  33. <th>Tasks</th>
  34. <th>&nbsp;</th>
  35. <th>Action</th>
  36. <th>&nbsp;</th>
  37. <th>Delete</th>
  38. <th>&nbsp;</th>
  39. </tr>
  40. </thead>
  41. <tbody>
  42. <?php
  43. $run_task = mysqli_query($db, "SELECT * FROM tasks LIMT 20");
  44. while ($row = mysql_fetch_assoc($run_task))
  45. {
  46. $id = $row['id'];
  47. $task1 = $row['task'];
  48.  
  49. ?>
  50. <tr>
  51.  
  52. <td>?php echo $id; ?> </td>
  53. <td>?php echo $task1; ?> </td>
  54. <td class = "delete"> <a href="index.php?delete=<?php echo $id;?>"> X</a></td>
  55. </tr>
  56.  
  57.  
  58. <?php } ?>
  59. </tbody>
  60. <?php
  61. if(isset($_GET['delete']))
  62. {
  63. $delete = $_GET['delete'];
  64. $query = "DELETE FROM tasks WHERE id = '$delete'";
  65. $run - mysqli_query($db,$query);
  66. if (!$run)
  67. {
  68. echo "this wont work";
  69. }
  70. else
  71. {
  72. header('location: index.php');
  73. }
  74. }
  75. ?>
  76. </table>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement