473,385 Members | 1,506 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

php and POST form not acting normal...

Hi All,

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.

Jul 17 '05 #1
1 1833
Alec wrote:
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:
<snip unindented code>
Any ideas?


Yes.
1. Indent your code.

2. Remove *all* error-suppressing '@'s from it.

3. Add the following lines to the top of your scripts:
error_reporting(E_ALL);
ini_set('display_errors', '1');

4. *always* check the return value of mysql_query() calls
$sql = "select a, b, c from table where id=4";
$x = mysql_query($sql)
or die("Error in query [$sql]: " . mysql_error());
Apart from this, if something is behaving the opposite way you intended,
maybe reversing the if() will have the desired effect.

if(isset($_SESSION[úsername'])) /* your version */
if(!isset($_SESSION[úsername'])) /* reversed version */
--
Mail to my "From:" address is readable by all at http://www.dodgeit.com/
== ** ## !! ------------------------------------------------ !! ## ** ==
TEXT-ONLY mail to the whole "Reply-To:" address ("My Name" <my@address>)
may bypass my spam filter. If it does, I may reply from another address!
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim ffitch | last post by:
Hi I have a main form with some fields directly on the form and others on a page of a Tab Control. On another page of the Tab Control I have a sub form. In the On Current event of my main form I...
0
by: Tat | last post by:
Hi, I am printing the form. The code is 100% accurate. It is the same as in MSDN, but in C#. ...
1
by: Manuel | last post by:
I have to log into a website and retrieve some information. The problem is that the post isn't "normal". I'm used to passing post values in the form of: Variable1=Value1&Variable2=Value2 etc. I...
7
by: | last post by:
Hello, I would like to do the following from a asp.net button click: <form method="POST" action="https://www.1234.com/trans_center/gateway/direct.cgi"> <input type="hidden" name="Merchant"...
0
by: WIWA | last post by:
Hi, I want to login to a password protected website and fetch the content of the page behind. I have based my code on http://weblogs.asp.net/jdennany/archive/2005/04/23/403971.aspx. When I use...
24
by: Sta12s | last post by:
First of all, I have NO idea what I'm doing - I'm a complete newb to Javascript and PHP so my code is going to look like crap ;) Now for my problem, I'm trying to do a little quiz with...
1
by: google | last post by:
I'm building a small ASPX page in C# to forward HTTP POST requests to another site. When the other site returns an HTTP error such as 404 or 405, I want to return that same HTTP status value to my...
2
by: MDANH2002 | last post by:
Hi From VB.NET I want to simulate the POST request of the following HTML form <html> <title>HTTP Post Testing</title> <body> <form action=http://www.example.com/postdata ...
3
by: Jag | last post by:
Hi I am facing a strange issue. I have 3 ASP pages in the default website 1. auth.aspx <html> <body>
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.