Forum Moderators: coopster

Message Too Old, No Replies

php post data lost

php post data lost

         

keskin

11:33 am on May 27, 2010 (gmt 0)

10+ Year Member



Hi all,

I have a simple form and a simple php script which is prints POST data. When I submit the form I get two different results. In result 1 everything is ok. But for result 2 i dont access POST data.
i submit the form repeatedly and when i submit the form in 1-2 sedonds i get result 2. but if i submit the form over 5 seconds i get result 2.

sorry my poor english. how do i fix this.

Im running Windows Server 2003 SP2 Apache/2.2.15 (Win32) mod_auth_sspi/1.0.4 PHP/5.2.9-1 Vmware 4.0

Here is the scripts and results:

form.php

<form name="test" id="test" method="post" action="process.php">
<input type="text" name="input01" id="input01" value="input01" /><br />
<input type="text" name="input02" id="input02" value="input02" /><br />
<input type="text" name="input03" id="input03" value="input03" /><br />
<input type="text" name="input04" id="input04" value="input04" /><br />
<input type="submit" />
</form>



process.php

<?php
echo '<pre>';
print_r($_POST);
?>



result 1

Array
(
[input01] => input01
[input02] => input02
[input03] => input03
[input04] => input04
)


result 2

Array
(
)

vincevincevince

11:53 am on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is that ALL there is on form.php ?

Matthew1980

11:57 am on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there keskin,

Firstly, you need to specify more attributes in the submit button:-

<input type="submit" name="submit" value="send form" />

Then in process.php you will need to do something like this:

<?php
if(isset($_POST['submit']) && ($_POST['submit'] == "send form")){
echo "<pre>";
print_r($_POST);
echo "</pre>";
}
else{
//redirect back to form as error has occured
header("location: YOUR_FORM_PAGE_HERE.php");
}
?>

Start with this and see what happens, this method will help you, but I don't understand why you need to repeatedly hit the submit button. If you do hit it, it will have nothing set :)

Also I notice as you have the text input's set with a default value - this is just for development stages isn't it? Don't forget that as soon as you enter data into the fields you will overwrite the default value..

Hope this helps..

[EDIT]: Hi there VinceVinceVince, I'm hoping as he has just posted the relevant detail, assuming as the structure is correct there..

Cheers,
MRb

Readie

12:52 pm on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Firstly, you need to specify more attributes in the submit button:-

<input type="submit" name="submit" value="send form" />

Not really true, it *might* be required for valid markup, but the form works fine either way.

Matthew1980

1:06 pm on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Readie,

Just habit I guess there, but always good practise to fill out properly ;-p But I am sure that you need to name the submit button in order for it to work (well definately if your checking the status), I could well be wrong though - sometimes I even check to see the form is set rather than the submit, either either I guess

I think the issue lyes in the recieving file - there was not conditional clause, so it relies on the globals being set, so no exception handler...

Cheers,
MRb

Readie

2:08 pm on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



But I am sure that you need to name the submit button in order for it to work (well definately if your checking the status)

You only need to name it if you want to see if the user clicked on it - it should only ever really be necessary when having 2 actions with one form (i.e. submit/preview) because the name/value of the submit button is only sent if the user clicks on it.

If I press return in a text input then I don't think the name/value of the submit button is sent.

I agree with you when you say the problem here is most likely with the lack of an exception handler, however.

rocknbil

8:14 pm on May 27, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard keskin, I can think of absolutely no reason why this should happen, there is nothing wrong with your code. I'm suspecting something with your server. Do you have a second test server you can load it on to give it a try?

Although it's very likely irrelevant, make sure the document validates [validator.w3.org], there is a slim possibility some missing quote somewhere else in the document is breaking the form. But this is extremely unlikely, if you get it to work once, it should work all the time.