How to create a forum in php asssitance


#1

Hey guys!

I am trying to make a php forum and have been following this tutorial:

I have the following errors:

image

but according to my url, it says that my error is in my post_reply_parse=error, which is in my other file…


This is the file for post_reply.php


<?php
include_once 'header.php';
if(!isset($_SESSION['u_uid'])) {
	header("Location: index.php?post_reply=notlogin");
	exit();
} else {
	$cid = $_GET['cid'];
	$tid = $_GET['tid'];



}
?>

<!DOCTYPE html>
<html>
<head>
	<title>	</title>
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form class="signup-form" action="post_reply_parse.php" method="POST">
<p>Reply Content</p>	
<br></br>
<textarea name="reply_content" rows="5" cols="75"></textarea>
<br></br>
<br></br>
<input type="hidden" name="cid" value="<?php echo $cid; ?>" />
<input type="hidden" name="tid" value="<?php echo $tid; ?>"/> 
<input type="submit" name="reply_submit" value="Post Your Reply">


</form>
</body>
</html>


// This is the code for post_reply_parse.php

<?php
include_once 'header.php';
if (!isset($_SESSION['u_uid'])) {
	header ("Location: index.php?post_reply_parse=notlogin");
	exit();
} else {
	if (!isset($_POST['submit'])) {
		header("Location: post_reply.php?post_reply_parse=error");
		exit();
	} else {
		include_once 'includes/dbh.php';
		$date = now();
		$creator = $_SESSION['u_uid'];
		$reply_content = $_POST['reply_content'];
		$cid = $_POST['cid'];
		$tid = $_POST['tid'];
		$limit = 1;

		$sql = "INSERT INTO posts (category_id, topic_id, post_creator, post_content, post_date) VALUES (?,?,?,?,?);";

		if (!mysqli_stmt_prepare($stmt, $sql)) {
				   echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "iisss", $cid, $tid, $creator, $reply_content, $date);
				    mysqli_stmt_execute($stmt);

				    $sql2 = "UPDATE categories
                             SET last_post_date = ?, last_user_posted = ?
                             WHERE id = ?
                             LIMIT ?
				             ";

				    if (!mysqli_stmt_prepare($stmt, $sql2)) {
				   echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "ssii", $date, $creator, $cid, $limit);
				    mysqli_stmt_execute($stmt);

				    $sql3 = "UPDATE topics
                             SET topic_reply_date = ?, topic_last_user = ?
                             WHERE id = ?
                             LIMIT ?
				            ";
                 	if (!mysqli_stmt_prepare($stmt, $sql3)) {
				      echo 'SQL error';
				   
				} else {
				    mysqli_stmt_bind_param($stmt, "ssii", $date, $creator, $tid, $limit);
				    mysqli_stmt_execute($stmt);

				    // Email Sending 


	}

	echo "<p>Your reply has been successfully posted. <a href='view_topic.php?cid=".$cid."&tid=".$tid."'>Click here to return to the topic.</a></p>";
}
}
 }
}

Should I use the backticks here to format my php?


#2

For some reason, I have figured out that the error lies here:

} else {
	if (!isset($_POST['submit'])) {
		header("Location: post_reply.php?post_reply_parse=error");
		exit();

	} else {

I am not sure but maybe I can’t have two else statements? just 1 if and 1 else? If i get rid of the above code then it does work…


#3

Sorry, it was my fault… the name is not called submit. I wrote the wrong name