This is my 'new_thread' page.
<?php
session_start();
require_once("includes/page.php");
require_once("includes/form.php");
require_once("includes/database.php");
$forum_id = $_GET['f'];
$user_id = $_SESSION['valid_userid'];
$submit = $_POST['submit'];
$thread_title = $_POST['title'];
$message = $_POST['message'];
$posted = time();
db_connect();
page_header("Mi World :: New Thread");
if(!isset($user_id))
{
echo("<p>You need to login to create a new thread.<p>");
}
elseif(isset($submit))
{
if(insert_thread_title())
{
if(show_thread())
{
$fetch_array_thread = mysql_fetch_array($result_thread);
$thread_id = $fetch_array_thread['thread_id'];
if(insert_reply())
{
echo("<p>Your thread was submitted.</p>");
}
else
{
echo("<p>Your message was not submitted at this time.".mysql_error()."</p>");
}
}
}
else
{
echo("<p>The thread could not be posted at this time.".mysql_error()."</p>");
}
}
else
{
new_thread();
}
mysql_close($conn);
page_footer();
?>
and this is my isert_thread_title() function
function insert_thread_title()
{
global $conn, $forum_id, $user_id, $thread_title, $posted;
$query = "INSERT INTO threads(forum_id,user_id, thread_title, posted)
VALUES('$forum_id','$user_id','$thread_title','$posted')";
$affected_thread_row = mysql_affected_rows($conn);
if($affected_thread_row > 0)
{
return true;
}
else
{
return false;
}
}
This is my 'insert_reply' function.
function insert_reply()
{
global $conn, $result, $thread_id, $user_id, $message, $posted;
$query = "INSERT INTO post(thread_id, user_id, message, posted)
VALUES('$thread_id','$user_id','$message','$posted')";
$result = mysql_query($query, $conn);
$affected_rows = mysql_affected_rows($conn);
if($affected_rows > 0)
{
return true;
}
else
{
return false;
}
}
and finally this is my 'show_thread' function
function show_thread()
{
global $conn, $thread_title, $forum_id, $result_thread;
$query = "SELECT * FROM threads
WHERE thread_title = $thread_title AND forum_id = $forum_id";
$result_thread = mysql_query($query, $conn);
$count = mysql_num_rows($result_thread);
if($count > 0)
{
return true;
}
else
{
return false;
}
}
The title of the thread is inserted successfully and is shown in the thread page. But the message is not inserted properly. I think it is because of the thread_id.
Thanks in advance.