Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

forum 'reply to post' submission / redirection problem
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

?>



Report this thread to moderator Post Follow-up to this message
Old Post
news.tpg.com.au
05-15-05 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 10:08 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.