prepare("SELECT * FROM news WHERE slug = ? LIMIT 1"); $stmt->bind_param("s", $slug); $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows === 0) { header("Location: /404.php"); exit; } $row = $result->fetch_assoc(); $news_id = $row['id']; // ✅ correct ID from DB ?> <?= htmlspecialchars($row['title']) ?>
<?= htmlspecialchars($row['title']) ?>

Leave a Comment

prepare( "INSERT INTO comments (news_id, name, email, comment) VALUES (?, ?, ?, ?)" ); $stmt->bind_param("isss", $news_id, $name, $email, $comment); $stmt->execute(); echo "

✅ Comment added successfully

"; } else { echo "

❌ All fields required

"; } } // ---------- Fetch Comments ---------- $stmt = $conn->prepare( "SELECT name, comment, created_at FROM comments WHERE news_id = ? ORDER BY created_at DESC" ); $stmt->bind_param("i", $news_id); $stmt->execute(); $comments = $stmt->get_result(); if ($comments->num_rows > 0): while ($c = $comments->fetch_assoc()): ?>

No comments yet.