| news.tpg.com.au 2005-05-15, 3:56 am |
| Hey PHPers/SQLers, just finished getting some code working for a 'reply to a
topic in a forum' working but having some problems with the redirection when
actually submitting the post.
Basically this code has two sections;
One is to display the form to actually reply to the original post topic and
the second is to submit the information using the same page by checking a
hidden variable. If the hidden variable op is not "addpost" it will show the
form, if op is "addpost" it will add the reply to the database.
The problem I'm having is that when submitting the form, although the data
goes into the database just fine, and when refreshing the posts page it
shows up OK, it looks like the page is still doing something, with the
progress bar constantly refreshing.
There are no errors but I imagine it would be in the final block of code.
When clicking on submit in the form it does not appear to be reaching the
lines:
header("Location: displaytopic.php?topicid=$topicid");
exit;
I'm using Windows 2000 with apache 1.3, PHP 4 and MySQL 4.1
Actual code follows. I have included the entire block if it helps anyone
else with forum issues and to help anyone troubleshooting this issue. Thanks
in advance.
---------------
<?php
// check for a connection to sql and the database
$conn = mysql_connect("localhost", "user", "password")
or die(mysql_error());
mysql_select_db("rdb", $conn)
or die(mysql_error());
if ($_POST[op] != "addpost")
{
if (!$_GET[postid])
{
header("Location: displaytopics.php");
exit;
}
// note: The below code creates forumtopics and forumposts as ft and fp as
the postid does not exist in the forumtopics table
$verify = "SELECT ft.topicid, ft.topictitle FROM
forumposts AS fp LEFT JOIN forumtopics AS ft ON
fp.topicid = ft.topicid WHERE fp.postid = $_GET[postid]";
$verifyres = mysql_query($verify, $conn)
or die(mysql_error());
if (mysql_num_rows($verifyres) < 1)
{
header("Location: displaytopics.php");
exit;
}
else
{
$topicid = mysql_result($verifyres, 0, 'topicid');
$topictitle = stripslashes(mysql_result($verifyres, 0, 'topictitle'));
echo "
<HTML>
<HEAD>
<TITLE>Post Your Reply in $topictitle</TITLE>
</HEAD>
<BODY>
<H1>Post your reply in $topictitle</H1>
<FORM METHOD=POST ACTION = \"$_SERVER[PHP_SELF]\">
<P><STRONG>Your E-mail Address: </STRONG><BR>
<INPUT TYPE=\"text\" NAME=\"postowner\" size=40 MAXLENGTH=150>
<P><STRONG>Post Text: </STRONG><BR>
<TEXTAREA NAME=\"posttext\" ROWS=8 COLS=40 WRAP=virtual></TEXTAREA>
<INPUT TYPE=\"hidden\" NAME=\"op\" VALUE=\"addpost\">
<INPUT TYPE=\"hidden\" NAME=\"topicid\" VALUE = \"$topicid\">
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Add Post\"></P>
</FORM>
</BODY>
</HTML>";
} // end of inner else statement
} // end of if addpost statement
else if ($_POST[op] == "addpost")
{
if ((!$_POST[topicid]) || (!$_POST[posttext]) || (!$_POST[postowner]))
{
header("Location: displaytopics.php");
exit;
}
// add the post
$addpost = "INSERT INTO forumposts values ('', '$_POST[topicid]',
'$_POST[posttext]', now(), '$_POST[postowner]')";
mysql_query($addpost, $conn)
or die(mysql_error());
/*
Redirect user to topic once the post has been added. Despite the above code
adding the data to the database,
the following lines just can't seem to be reached - weird...
*/
header("Location: displaytopic.php?topicid=$topicid");
exit;
} // end of else if addpost statement
?>
|