36947-vm/post.php
Flatlogic Bot 4be8924eba Educ8
2025-12-14 21:05:45 +00:00

40 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/db/config.php';
$post = null;
$slug = $_GET['slug'] ?? null;
if ($slug) {
try {
$pdo = db();
$stmt = $pdo->prepare("SELECT * FROM posts WHERE slug = ?");
$stmt->execute([$slug]);
$post = $stmt->fetch();
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
}
if (!$post) {
http_response_code(404);
$pageTitle = 'Post Not Found';
require_once __DIR__ . '/includes/header.php';
echo "<h1>Post Not Found</h1><p>Sorry, the post you are looking for does not exist.</p>";
require_once __DIR__ . '/includes/footer.php';
exit;
}
$pageTitle = $post['title'];
require_once __DIR__ . '/includes/header.php';
?>
<article>
<h1><?php echo htmlspecialchars($post['title']); ?></h1>
<p class="text-muted">By <?php echo htmlspecialchars($post['author']); ?> on <?php echo date('F j, Y', strtotime($post['created_at'])); ?></p>
<div><?php echo nl2br(htmlspecialchars($post['content'])); ?></div>
</article>
<a href="/" class="btn btn-primary mt-4">Back to Blog</a>
<?php require_once __DIR__ . '/includes/footer.php'; ?>