prepare($sql)) { $stmt->bind_param("s", $forum_title); $stmt->execute(); $stmt->close(); } } // Handle new comment submission if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['comment']) && !empty($_POST['comment'])) { $forum_id = $_POST['forum_id']; $username = $_SESSION['username']; $comment = $_POST['comment']; // Insert comment into the forum_comments table (change from comments to forum_comments) $sql = "INSERT INTO forum_comments (forum_id, username, comment) VALUES (?, ?, ?)"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("iss", $forum_id, $username, $comment); $stmt->execute(); $stmt->close(); } } // Handle forum deletion if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete_forum'])) { $forum_id = $_POST['forum_id']; $sql = "DELETE FROM forums WHERE id = ?"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("i", $forum_id); $stmt->execute(); $stmt->close(); } } // Handle comment deletion if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['delete_comment'])) { $comment_id = $_POST['comment_id']; $sql = "DELETE FROM forum_comments WHERE id = ?"; if ($stmt = $link->prepare($sql)) { $stmt->bind_param("i", $comment_id); $stmt->execute(); $stmt->close(); } } // Fetch all forums $sql = "SELECT id, title, created_at FROM forums ORDER BY created_at DESC"; $forums = []; if ($result = $link->query($sql)) { while ($row = $result->fetch_assoc()) { $forums[] = $row; } $result->free(); } ?>
$comment