Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="card mb-3">
- <div class="card-header">
- Dodaj swoją opinię
- </div>
- <div class="card-body">
- <?php
- if (isset($_POST['opinia'])) {
- $opinia = $_POST['opinia'];
- $ip = $_SERVER['REMOTE_ADDR'];
- if (mb_strlen($opinia) >= 5 && mb_strlen($opinia) <= 200) {
- $stmt = $dbh->prepare("INSERT INTO guest_book (opinion, ip, created) VALUES (:opinion, :ip, NOW())");
- $stmt->execute([':opinion' => $opinia, ':ip' => $ip]);
- }
- }
- if (isset($_GET['delete'])) {
- $id = $_GET['delete'];
- $stmt = $dbh->prepare("SELECT id, ip FROM guest_book WHERE id = :id");
- $stmt->execute([':id' => $id]);
- $row = $stmt->fetch(PDO::FETCH_ASSOC);
- if ($row['ip'] == $_SERVER['REMOTE_ADDR']) {
- $stmt = $dbh->prepare("DELETE FROM guest_book WHERE id = :id");
- $stmt->execute([':id' => $id]);
- }
- }
- ?>
- <form action="index.php?page=guest_book" method="POST">
- <input type="textarea" name="opinia" placeholder="Co Ci chodzi po głowie?">
- <input type="submit" value="Dodaj">
- </form>
- </div>
- </div>
- <div class="card mb-3">
- <div class="card-header">
- Wpisy gości
- </div>
- <div class="card-body">
- <table class="table table-striped">
- <thead>
- <tr id="wiersz-naglowka">
- <th scope="col">ID</th>
- <th scope="col">Opinia</th>
- <th scope="col">Adres</th>
- <th scope="col">Dodano</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $stmt = $dbh->prepare("SELECT id, opinion, ip, created FROM guest_book");
- $stmt->execute();
- while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
- if ($_SERVER['REMOTE_ADDR'] == $row['ip']) {
- print '
- <tr>
- <td>' . intval($row['id']) . '</td>
- <td>' . htmlspecialchars($row['opinion'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- <td>' . htmlspecialchars($row['ip'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- <td>' . htmlspecialchars($row['created'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- <td><button><a href="index.php?page=guest_book&delete=' . $row['id'] . '"> Usuń </a></button></td>
- </tr>';
- } else {
- print '
- <tr>
- <td>' . intval($row['id']) . '</td>
- <td>' . htmlspecialchars($row['opinion'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- <td>' . htmlspecialchars($row['ip'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- <td>' . htmlspecialchars($row['created'], ENT_QUOTES | ENT_HTML401, 'UTF-8') . '</td>
- </tr>';
- }
- }
- ?>
- </tbody>
- </table>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement