prepare("INSERT INTO comments (post_id, name, comment) VALUES (?, ?, ?)"); $stmt->execute([$post_id, $name, $comment_text]); header("Location: post.php?id=" . $post_id); exit; } catch (PDOException $e) { error_log("DB Error: " . $e->getMessage()); } } } $post = null; $comments = []; try { $pdo = db(); // Fetch post $stmt = $pdo->prepare("SELECT * FROM posts WHERE id = ?"); $stmt->execute([$post_id]); $post = $stmt->fetch(); // Fetch comments $stmt = $pdo->prepare("SELECT * FROM comments WHERE post_id = ? ORDER BY created_at DESC"); $stmt->execute([$post_id]); $comments = $stmt->fetchAll(); } catch (PDOException $e) { error_log("DB Error: " . $e->getMessage()); } // If no post is found, redirect to the homepage if (!$post) { header("Location: index.php"); exit; } ?> <?php echo htmlspecialchars($post['title']); ?> - My Awesome Blog
My Awesome Blog

Posted on
Hero image for the blog post titled '<?php echo htmlspecialchars($post['title']); ?>'
...
← Back to all posts
© My Awesome Blog. All Rights Reserved.