Advertisement
Guest User

Untitled

a guest
Sep 27th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <?php
  2. $con=mysqli_connect("localhost","table","password","database");
  3. if (mysqli_connect_errno())
  4. {
  5. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  6. }
  7. $result = mysqli_query($con,"SELECT * FROM recetas_galletas");
  8. echo "<table border='1'>
  9. <tr>
  10. <th>Title</th>
  11. <th>Description</th>
  12. </tr>";
  13.  
  14. while($row = mysqli_fetch_array($result))
  15. {
  16. echo "<tr>";
  17. echo "<td>" . $row['title'] . "</td>";
  18. echo "<td>" . $row['description'] . "</td>";
  19. echo "<td>" . DELETE BUTTON "</td>";
  20. echo "</tr>";
  21. }
  22. echo "</table>";
  23. mysqli_close($con);
  24. ?>
  25.  
  26. <?php
  27. $con = mysqli_connect("localhost","table","password","database");
  28. // Check connection
  29. if (mysqli_connect_errno())
  30. {
  31. die("Failed to connect to MySQL: " . mysqli_connect_error());
  32. }
  33.  
  34. if (!$result = mysqli_query($con,"SELECT * FROM recetas_galletas"))
  35. {
  36. die("Error: " . mysqli_error($con));
  37. }
  38. ?>
  39. <table border='1'>
  40. <tr>
  41. <th>Title</th>
  42. <th>Description</th>
  43. </tr>
  44. <?php
  45. while($row = mysqli_fetch_array($result))
  46. {
  47. ?>
  48. <tr>
  49. <td><?php echo $row['title']; ?></td>
  50. <td><?php echo $row['description']; ?></td>
  51. <td><a href="delete.php?id=<?php echo $row['id']; ?>">Delete</a></td>
  52. </tr>
  53. <?php
  54. }
  55. mysqli_close($con);
  56. ?>
  57. </table>
  58.  
  59. <?php
  60. // Your database info
  61. $db_host = '';
  62. $db_user = '';
  63. $db_pass = '';
  64. $db_name = '';
  65.  
  66. if (!isset($_GET['id']))
  67. {
  68. echo 'No ID was given...';
  69. exit;
  70. }
  71.  
  72. $con = new mysqli($db_host, $db_user, $db_pass, $db_name);
  73. if ($con->connect_error)
  74. {
  75. die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
  76. }
  77.  
  78. $sql = "DELETE FROM recetas_galletas WHERE id = ?";
  79. if (!$result = $con->prepare($sql))
  80. {
  81. die('Query failed: (' . $con->errno . ') ' . $con->error);
  82. }
  83.  
  84. if (!$result->bind_param('i', $_GET['id']))
  85. {
  86. die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
  87. }
  88.  
  89. if (!$result->execute())
  90. {
  91. die('Execute failed: (' . $result->errno . ') ' . $result->error);
  92. }
  93.  
  94. if ($result->affected_rows > 0)
  95. {
  96. echo "The ID was deleted with success.";
  97. }
  98. else
  99. {
  100. echo "Couldn't delete the ID.";
  101. }
  102. $result->close();
  103. $con->close();
  104.  
  105. echo "<td><a href='http://www.site.com/delete.php?id=" . $row['id'] . "'></td>";
  106.  
  107. if (is_int($_GET["id"]) {
  108. $query = "DELETE FROM recetas_galletas WHERE id = " . $_GET["id"];
  109. $result = mysqli_query($con, $query);
  110. // Check the result and post confirm message
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement