]> git.bochard.net Git - mysite.git/commitdiff
new guestbook!
authorbochard <git@bochard.net>
Sun, 21 Dec 2025 06:17:12 +0000 (14:17 +0800)
committerbochard <git@bochard.net>
Sun, 21 Dec 2025 06:17:12 +0000 (14:17 +0800)
guestbook.php
index.php

index d47d28e10819892d31f31a295bb866421077bce9..432dce6337c90fd5368efd084e221a1f9a6f194d 100644 (file)
@@ -6,33 +6,98 @@
        $pgjs = [];
        head($pgtitle, $pgdescription, $pgcss, $pgjs);
 ?>
-<body background="/image/background/bluesky.jpg" style="color: #fcff36;">
+<body background="/image/background/bluesky.jpg">
        <center>
                <table>
                        <tr>
                                <td>
-                                       <center><img src="/image/gif/guestbook.gif"></center>
+                                       <center><img src="/image/gif/guestbook.gif" width="200"></center>
                                        
                                        <?php
+                                               error_reporting(E_ALL);
+                                               ini_set("display_errors", 1);
+                                       
+                                               // database config.
+                                               $host = "localhost";
+                                               $dbname = "guestbook";
+                                               $username = "";
+                                               $password = "";
+                                       
+                                               // connect to database
+                                               $conn = new mysqli($host, $username, $password, $dbname);
+                                               
+                                               // check connection
+                                               if($conn->connect_error){
+                                                       die("Connection failed: {$conn->connect_error}");
+                                               }
+                                               
+                                               // entry submission
                                                if ($_SERVER["REQUEST_METHOD"] == "POST"){
-                                                       $name = $POST['name'];
-                                                       $website = $POST['website'];
-                                                       $email = $POST['email'];
-                                                       $comment = $POST['comment'];
+                                                       $name = $_POST['name'];
+                                                       $country = $_POST['country'];
+                                                       $website = $_POST['website'];
+                                                       $email = $_POST['email'];
+                                                       $comment = $_POST['comment'];
+                                                       $ip_addr = $_SERVER['REMOTE_ADDR'];
+                                                       
+                                                       // query
+                                                       $sql = "INSERT INTO entries (name, country, website, email, comment, ip_addr)
+                                                                                       VALUES ('$name', '$country', '$website', '$email', '$comment', '$ip_addr');";
+                                                       $conn->query($sql); // submit query
+                                                       
+                                                       header("Location: " . $_SERVER["PHP_SELF"]);
+                                                       die();
                                                };
+                                               
+                                               $result = $conn->query("SELECT name, country, website, email, comment, written_at
+                                                                                                                                               FROM entries
+                                                                                                                                               WHERE status='visible'
+                                                                                                                                               ORDER BY written_at DESC;");
                                        ?>
                                        
-                                       <form method="POST" action="<?= htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
-                                               <label for"name">Name: </label><input type="text" name="name" required>
-                                               <br>
-                                               <label for"website">My website: </label><input type="text" name="website" placeholder="optional">
-                                               <br>
-                                               <label for"email">My e-mail: </label><input type="email" name="email" placeholder="optional">
-                                               <br>
-                                               <label for="comment">Comment: </label><br><textarea rows="10" cols="35" required></textarea>
-                                               <br>
-                                               <button type="submit">Sign in the guestbook</button>
-                                       </form>
+                                       <center>
+                                               <form method="POST" action="<?= htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
+                                                       <label for="name">Name: </label><input type="text" name="name" required>
+                                                       <br>
+                                                       <label for="country">Country: </label><input type="text" name="country" placeholder="optional">
+                                                       <br>
+                                                       <label for="website">My website: </label><input type="text" name="website" placeholder="optional">
+                                                       <br>
+                                                       <label for="email">My e-mail: </label><input type="email" name="email" placeholder="only me can see">
+                                                       <br>
+                                                       <label for="comment">Comment: </label><br><textarea name="comment" rows="10" cols="35" required></textarea>
+                                                       <br>
+                                                       <button type="submit">Sign the guestbook</button>
+                                               </form>
+                                       </center>
+                                       
+                                       <br><br>
+                                       
+                                       <center><h2>Entries</h2></center>
+                                       <table border="1" cellspacing="" width="600">
+                                               <tr>
+                                                       <th>Name</th>
+                                                       <th>Country</th>
+                                                       <th>Web site</th>
+                                                       <th>Comment</th>
+                                               </tr>
+                                       <?php
+                                               if($result && $result->num_rows > 0){
+                                                       while($row = $result->fetch_assoc()){
+                                                               echo "<tr>";
+                                                                       echo "<td>" . htmlspecialchars($row['name']) . "</td>";
+                                                                       echo "<td>" . htmlspecialchars($row['country']) . "</td>";
+                                                                       if(!empty($row['website'])){
+                                                                               echo "<td><a href='" . htmlspecialchars($row['website']) . "' target='_blank'>" . htmlspecialchars($row['website']) . "</a></td>";
+                                                                       } else{
+                                                                               echo "<td></td>";
+                                                                       }
+                                                                       echo "<td>" . htmlspecialchars($row['comment']) . "</td>";
+                                                               echo "</tr>";
+                                                       }
+                                               }
+                                       ?>
+                                       </table>
                                        
                                        <br><br>
                                        <center><a href="/"><img src="/image/navigation/backhomepage.gif"></a></center>
index f382ae6d6297b4e322f612724378c1149031a302..705c7ff9441f96cac1b48b016efa082992853ec9 100644 (file)
--- a/index.php
+++ b/index.php
                                                                                                <th>update description</th>\r
                                                                                                <th>date</th>\r
                                                                                        </tr>\r
+                                                                                       <tr bgcolor="#ffffff">\r
+                                                                                               <td>the site has now its own guestbook</td>\r
+                                                                                               <td>Dec/21/2025</td>\r
+                                                                                       </tr>\r
                                                                                        <tr bgcolor="#ffffff">\r
                                                                                                <td>new layout!!</td>\r
                                                                                                <td>Dec/15/2025</td>\r