I have recently built a site using PHP and MySQL, and started to
implement a basic forum into it. However, the form to post messages
doesnt do what I want it to. If there is no user logged in (ie no
session) then it posts the message fine. But if there is a user logged
in, it loads my login.php page instead of my post.php page??? Code for
both pages below:
>>>>>READ.PHP>>>>>>>>>
<?php
session_start();
include("mngmnt.inc");
connect_to_db();
@$threadid=$_GET['thread'];
$_SESSION['page']="Forum - Read/Post";
print_header();
print_menu();
print "<form method=\"POST\" action=\"post.php\">\n
<input name=\"thrid\" type=\"hidden\" value=\"".$threadid."\">\n";
if($threadid=="new")
{
print "<center><table width=\"400\"><tr><th width=\"*\"
align=\"left\">Post:</th></tr>\n
<tr><td width=\"100%\" align=\"center\">Subject: <input
name=\"thread\" type=\"text\" size=\"60\"></td></tr>\n";
}
else
{
$threaddata=mysql_query("SELECT created, date, starter, username,
area, thread, body FROM forum WHERE tid='".$threadid."' ORDER BY
created LIMIT 1");
while($row=mysql_fetch_array($threaddata))
{
extract($row);
print "<a href=\"forum.php?area=$area\">$area</a> - <b>$thread</b>
(Started by ";
contact($starter);
print ")<p>\n";
}
$threaddata=mysql_query("SELECT created, date, username, body FROM
forum WHERE tid='".$threadid."' ORDER BY created");
while($row=mysql_fetch_array($threaddata))
{
extract($row);
print "<table width=\"100%\" columns=\"2\"><tr><th width=\"*\"
align=\"left\">By ";
contact($username);
print "</th><th width=\"225\" align=\"right\">Posted on ";
mysql_timestamp_to_human_basic($created);
print "</th></tr>\n
<tr><td align=\"left\">$body</td><td align=\"right\"
valign=\"bottom\">Last edited: ";
mysql_timestamp_to_human_basic($date);
print "</td></tr></table><p>\n<center><table width=\"400\"><tr><th
width=\"*\" align=\"left\">Reply:</th></tr>\n";
}
}
if(isset($_SESSION['username']))
{
print "<tr><td width=\"100%\" align=\"center\"><textarea
name=\"postbody\" cols=\"50\" rows=\"10\"></textarea></td></tr>\n
<tr><td align=\"center\"><input name=\"postsubmit\" type=\"submit\"
value=\"Post\"><input type=\"reset\"
value=\"Clear\"></td></tr></table>\n
</form>\n
</center>\n";
}
else
print "Login to reply</center>";
print_menu_right();
print_footer();
?>
>>>POST.PHP>>>>>>>>>
<?php
session_start();
include("mngmnt.inc");
connect_to_db();
@$thrid=$_POST['thrid'];
@$postbody=$_POST['postbody'];
@$logpost=$_POST['postsubmit'];
if($logpost=="Post")
{
$ts=timestamp_to_mysql();
if($thrid=="new")
{
}
else
{
$threaddata=mysql_query("SELECT starter, aid, area, thread FROM forum
WHERE tid='".$thrid."' LIMIT 1");
while($row1=mysql_fetch_array($threaddata))
{
extract($row1);
$putpost=mysql_query("INSERT INTO forum(created, date, starter,
username, aid, area, tid, thread, body) values(".$ts.", ".$ts.",
'".$starter."', '".$_SESSION['username']."', ".$aid.", '".$area."',
".$thrid.", '".$thread."', '".$postbody."')") or die(mysql_error());
if(!$putpost)
print "ERROR PUTTING POST";
else
print "<html>\n<head>\n<meta http-equiv=\"Refresh\" content=\"10;
url=read.php?thread=$tid\">\n</head>\n<body>\nPost Complete. Now
returning to the thread, please wait...\n</body>\n</html>\n";
}
}
}
mysql_close();
?>
>>>>>>>>>>>>
Any ideas?
TIA.
Alec.