473,545 Members | 2,291 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P HP>>>>>>>>>
<?php
session_start() ;
include("mngmnt .inc");
connect_to_db() ;
@$threadid=$_GE T['thread'];
$_SESSION['page']="Forum - Read/Post";

print_header();
print_menu();

print "<form method=\"POST\" action=\"post.p hp\">\n
<input name=\"thrid\" type=\"hidden\" value=\"".$thre adid."\">\n";
if($threadid==" new")
{
print "<center><t able 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=mys ql_query("SELEC T created, date, starter, username,
area, thread, body FROM forum WHERE tid='".$threadi d."' ORDER BY
created LIMIT 1");
while($row=mysq l_fetch_array($ threaddata))
{
extract($row);
print "<a href=\"forum.ph p?area=$area\"> $area</a> - <b>$thread</b>
(Started by ";
contact($starte r);
print ")<p>\n";
}
$threaddata=mys ql_query("SELEC T created, date, username, body FROM
forum WHERE tid='".$threadi d."' ORDER BY created");
while($row=mysq l_fetch_array($ threaddata))
{
extract($row);
print "<table width=\"100%\" columns=\"2\">< tr><th width=\"*\"
align=\"left\"> By ";
contact($userna me);
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<cen ter><table width=\"400\">< tr><th
width=\"*\" align=\"left\"> Reply:</th></tr>\n";
}
}

if(isset($_SESS ION['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=\"postsubm it\" 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_righ t();
print_footer();
?>
>>>POST. PHP>>>>>>>>>
<?php
session_start() ;
include("mngmnt .inc");
connect_to_db() ;
@$thrid=$_POST['thrid'];
@$postbody=$_PO ST['postbody'];
@$logpost=$_POS T['postsubmit'];

if($logpost=="P ost")
{
$ts=timestamp_t o_mysql();
if($thrid=="new ")
{
}
else
{
$threaddata=mys ql_query("SELEC T starter, aid, area, thread FROM forum
WHERE tid='".$thrid." ' LIMIT 1");
while($row1=mys ql_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?th read=$tid\">\n</head>\n<body>\n Post Complete. Now
returning to the thread, please wait...\n</body>\n</html>\n";
}
}
}
mysql_close();
?>
>>>>>>>> >>>>


Any ideas?

TIA.

Alec.

Jul 17 '05 #1
1 1839
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('displa y_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($sq l)
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($_SESS ION[úsername'])) /* your version */
if(!isset($_SES SION[ú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
1142
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 have some code that refers to a field on the sub form. Under normal circumstances this works fine. If I then select a field directly on the main...
0
1328
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#. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vbcode/html/vbtskCodeExamplePrintingForm.asp What happens is that if during printing any window happens to be on the top
1
2960
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 used Live Http Headers to retrieve the POST information, I included it at the end of this message. Can anyone tell me how to make THIS kind of post?...
7
4247
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" value="Merchant Name"> <input type="hidden" name="OrderID" value="Unique OrderID value"> <input type="hidden" name="email" value="Customers email...
0
3862
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 tools like ieHTTPHeaders v1.6, and I perform a normal login (using the normal website), I see that the viewstate is...
24
1892
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 Javascript but I would like to pass along the varibles to a php file (for some reason I have a feeling it would be easier) I'm trying to gather the...
1
6436
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 caller. But when I do so, my caller always reports HTTP error 500. How can I return the actual HTTP status that I received? Here is my code: ...
2
6280
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 enctype="multipart/form-data" method="post" name="testform">
3
5029
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>
0
7465
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7416
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7752
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5969
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1878
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
701
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.