homepage Welcome to WebmasterWorld Guest from 54.197.183.230
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP not remembering $ POST variables
$_POST variables dissapearing
Seamless

5+ Year Member



 
Msg#: 3084065 posted 10:11 am on Sep 15, 2006 (gmt 0)

Hi,

I wonder if any one can help me..

I am developing a drawing register for the company i work for on our intranet. We recently got a new server (Windows 2003), so i installed PHP and MySQL on it.

When a user fills in a web form (i'll call it form.php) on the intranet i make the form post the variables to another file (form-parse.php) which parses the data. If they have not entered the required information i display the form errors on the form-parse.php telling them to go back to the original form and correct them.

My problem is that when they click the back button on the browser the $_POST variables are lost from the form.

I have included value="<? echo $_POST[variable1];?>" for each of the relevant <input> tags in the original form, so i know its not that.

Could it be a setting in the php.ini file or is this something to do with the server settings and this post is in the wrong forum completely.

Thanks in advance

Seamless

 

barns101

5+ Year Member



 
Msg#: 3084065 posted 11:56 am on Sep 15, 2006 (gmt 0)

The data has been POSTed to form-parse.php (not form.php) and so no post array exists for form.php and this is why it's not working as expected.

You could start a session and save the post data in the session array and so then if you needed to go back to form.php you could call the values from the session data.

lasko

10+ Year Member



 
Msg#: 3084065 posted 1:34 pm on Sep 15, 2006 (gmt 0)

You could post it to the same page and us an IF statement to include the process form script when Form was submbitted.

pixeltierra

5+ Year Member



 
Msg#: 3084065 posted 5:09 pm on Sep 15, 2006 (gmt 0)

In plain english, the $_POST array is not sent back to the form page by using the back button (I wish it were that easy). I'll tell you a trick I use.

The default action for forms is the very same page that they are on. Submit the form to the form page and combine the form and form parsing code. It will look something like this:

if ($_POST) {
process data and show results...
if (errors in data) {
$prev_values = $_POST;
}
end script...
}

<form method="post">
<input name="thing" value=" <?php echo $prev_values['thing'];?>">

...
You use $prev_values to re-populate the form. If there was no $prev_values nothing is printed.

Good luck

Seamless

5+ Year Member



 
Msg#: 3084065 posted 12:23 pm on Sep 19, 2006 (gmt 0)

Thanks for your replies, i have managed to work my way around it, however i experimented a little and found the following results.

On the companies intranet server:
I took all the php code out of form.php and renamed it to form.html.

When i filled out the form on form.html and clicked submit (making sure i missed out a required field) form-parse.php throws up an error (as it should). I then clicked the back button on the browser and i didn't need to fill the form in again, the previous data i entered was already there.

On a web server I pay for:
I uploaded form.php and form-parse.php to the external server that i have a website hosted on and the whole thing works as it should.

So i shouldn't have to add any extra code to the users data back in the form. Which is why this is puzzling me because i have never needed to do it on other servers.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved