Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
require_once 'testconnect.php';
// Get all messages ordered by newest first
$stmt = $conn->prepare('SELECT * FROM `messages` ORDER BY `created_at` DESC');
$stmt->execute();
// Fetching results
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Loop through the results and do something with them
foreach ($results as $row) {
$name = $row['name'];
$message = $row['message'];
$imagePath = $row['imagePath'];
// Format the timestamp
$timestamp = isset($row['created_at']) ? date('d-m-Y H:i', strtotime($row['created_at'])) : '';
// Display the message
echo "
<div class='msg1'>
<div class='msg-content'>
<h4>" . htmlspecialchars($name) . "</h4>
<p>" . nl2br(htmlspecialchars($message)) . "</p>";
// Only show image if path exists
if (!empty($imagePath)) {
echo "<img src='" . htmlspecialchars($imagePath) . "' class='textIMG' alt='Afbeelding van " . htmlspecialchars($name) . "'/>";
}
// Show timestamp
if (!empty($timestamp)) {
echo "<div class='timestamp'>$timestamp</div>";
}
echo "</div></div>";
}