Hey guys!
I am trying to create a php forum by watching this tutorial but I have the following error on my page but can’t figure out what is wrong:
I have the following error:
But I have sql error:
<?php
include_once 'header.php';
if (!isset($_SESSION['u_uid'])) {
header("Location: index.php?view_category=notlogin");
exit();
} else {
include_once 'includes/dbh.php';
$cid = $_GET['cid'];
$logged = " <a href='create_topic.php?cid=".$cid."'>Click here to create a topic</a>";
}
$limit = 1;
$sql = "SELECT id FROM categories WHERE id= ? LIMIT =?";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'SQL error';
} else {
mysqli_stmt_bind_param($stmt, "ii", $cid, $limit);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck ==1) {
$sql2 = "SELECT * FROM topics WHERE category_id= ? ORDER BY topic_reply_date DESC;";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql2)) {
echo 'SQL error';
} else {
mysqli_stmt_bind_param($stmt, "i", $cid);
mysqli_stmt_execute($stmt);
$result2 = mysqli_stmt_get_result($stmt);
$resultCheck2 = mysqli_num_rows($result2);
if ($resultCheck2 > 0) {
$topics .= "<table width='100%' style='border-collapse: collapse:'>";
$topics .= "<tr><td colspan='3'><a href='forum.php'>Return to Forum Index</a>".$logged."</td></tr>";
$topics .= "<tr style='background-color: #dddddd:'><td>Topic Title</td>><td width='65' align='center'>Replies</td><td width='65' align='center'>Views</td></tr>";
$topics .= "<tr><td colspan='3'><hr></td></tr>";
while ($row = mysqli_fetch_assoc($result2)) {
$tid = $row['id'];
$title = $row['topic_title'];
$views = $row['topic_views'];
$date = $row['topic_date'];
$creator = $row['topic_creator'];
$topics .= "<tr><td><a href='view_topic.php?cid=".$cid."&tid=".$tid."'>".$title."</a><br /><span class='post_info'>Posted by: ".$creator." on ".$date."</span></td><td align='center'>0</td><td align='center'>".$views."</td></tr>";
$topics .= "<tr><td colspan='3'><hr /></td></tr>";
}
$topics .= "</table>";
echo $topics;
} else {
echo "<a href='header.php'>Return to the Forum page</a>";
echo "<p> There are no topics in this Category yet.".$logged."</p>";
}
}
}else {
echo "<a href='header.php'>Return to the Forum page</a>";
echo "<p> You are trying to view a catebory that does not exists yet.</p>";
}
}