Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. <div class="card mb-3">
  2. <div class="card-header">
  3. Dodaj swoją opinię
  4. </div>
  5. <div class="card-body">
  6.  
  7. <?php
  8.  
  9. if (isset($_POST['opinia'])) {
  10. $opinia = $_POST['opinia'];
  11. $ip = $_SERVER['REMOTE_ADDR'];
  12. if (mb_strlen($opinia) >= 5 && mb_strlen($opinia) <= 200) {
  13.  
  14. $stmt = $dbh->prepare("INSERT INTO guest_book (opinion, ip, created) VALUES (:opinion, :ip, NOW())");
  15. $stmt->execute([':opinion' => $opinia, ':ip' => $ip]);
  16. }
  17. }
  18.  
  19. if (isset($_GET['delete'])) {
  20. $id = $_GET['delete'];
  21. $stmt = $dbh->prepare("SELECT id, ip FROM guest_book WHERE id = :id");
  22. $stmt->execute([':id' => $id]);
  23. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  24. if ($row['ip'] == $_SERVER['REMOTE_ADDR']) {
  25. $stmt = $dbh->prepare("DELETE FROM guest_book WHERE id = :id");
  26. $stmt->execute([':id' => $id]);
  27. }
  28. }
  29.  
  30.  
  31. ?>
  32. <form action="index.php?page=guest_book" method="POST">
  33. <input type="textarea" name="opinia" placeholder="Co Ci chodzi po głowie?">
  34. <input type="submit" value="Dodaj">
  35. </form>
  36. </div>
  37. </div>
  38. <div class="card mb-3">
  39. <div class="card-header">
  40. Wpisy gości
  41. </div>
  42. <div class="card-body">
  43. <table class="table table-striped">
  44. <thead>
  45. <tr id="wiersz-naglowka">
  46. <th scope="col">ID</th>
  47. <th scope="col">Opinia</th>
  48. <th scope="col">Adres</th>
  49. <th scope="col">Dodano</th>
  50. </tr>
  51. </thead>
  52. <tbody>
  53. <?php
  54. $stmt = $dbh->prepare("SELECT id, opinion, ip, created FROM guest_book");
  55. $stmt->execute();
  56. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
  57.  
  58. if ($_SERVER['REMOTE_ADDR'] == $row['ip']) {
  59. print '
  60. <tr>
  61. <td>' . intval($row['id']) . '</td>
  62. <td>' . htmlspecialchars($row['opinion'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  63. <td>' . htmlspecialchars($row['ip'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  64. <td>' . htmlspecialchars($row['created'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  65. <td><button><a href="index.php?page=guest_book&delete=' . $row['id'] . '"> Usuń </a></button></td>
  66. </tr>';
  67. } else {
  68. print '
  69. <tr>
  70. <td>' . intval($row['id']) . '</td>
  71. <td>' . htmlspecialchars($row['opinion'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  72. <td>' . htmlspecialchars($row['ip'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  73. <td>' . htmlspecialchars($row['created'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
  74. </tr>';
  75. }
  76. }
  77. ?>
  78. </tbody>
  79. </table>
  80. </div>
  81. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement