Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
include "/XAMPP/htdocs/guestbook/connection.php";
try {
$conn = new PDO("mysql:host=$host;database=$database", $username, $password);
// Zet PDO in de foutmodus om uitzonderingen te genereren
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// Voorbereiden van de query om gegevens op te halen
$stmt = $conn->prepare("SELECT * FROM guestbook ORDER BY timestamp DESC");
// Uitvoeren van de query
$stmt->execute();
$comments = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($comments) > 0) {
foreach ($comments as $comment) {
echo '<div class="comment">';
echo '<h3>' . htmlspecialchars($comment['name']) . '</h3>';
echo '<p>' . htmlspecialchars($comment['message']) . '</p>';
if (!empty($comment['image'])) {
echo '<img src="uploads/' . htmlspecialchars($comment['image']) . '" alt="User Image">';
}
echo '<p>Posted on ' . date('F j, Y, g:i a', strtotime($comment['timestamp'])) . '</p>';
echo '</div>';
}
} else {
echo '<p>No comments yet.</p>';
}
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>