Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
if (!$_SESSION['admin_logged_in']) {
header("Location: admin_login.php");
exit();
}
// Include database connection
require_once('connection.php');
try {
// Select data from the guestbook table
$stmt = $pdo->prepare("SELECT * FROM guestbook ORDER BY gasten_datum DESC");
$stmt->execute();
// Fetch all rows as an associative array
$guestbookEntries = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
</head>
<body>
<h2>Welcome, Admin</h2>
<h3>Guestbook Entries:</h3>
<table>
<tr>
<th>Name</th>
<th>Message</th>
<th>Date</th>
<th>Action</th>
</tr>
<?php foreach ($guestbookEntries as $entry): ?>
<tr>
<td><?php echo $entry['gasten_naam']; ?></td>
<td><?php echo $entry['gasten_bericht']; ?></td>
<td><?php echo date("d-M-Y H:i", strtotime($entry['gasten_datum'])); ?></td>
<td><a href="delete_entry.php?entry_id=<?php echo $entry['id']; ?>">Delete</a></td>
</tr>
<?php endforeach; ?>
</table>
<br>
<a href="logout.php">Logout</a>
</body>
</html>