Page 1 of 1

Small problem with sessions

Posted: Thu Apr 10, 2003 1:28 pm
by leebo
OK i have page1.php with form fields filled in with data from mysql.

<input type="text" name="location" size="30" value="<? echo($row[18]);?>"> etc.etc..........

I use the following to validate user:

<? session_start();
if ( session_is_registered ("myuser") )
{


when the form goes to the other page ( page2.php ) the data is displayed on page2 fine but.................

If they decide to go back and change something on page1.php when sent to page2 again the changes have not been applied because of the session saves the values from page1 on the first submit......

How can i change the session so it will keep changing values if they hit the back button ? Or will a refresh work on page2 ? if so whats the code ??

Thanks

Posted: Thu Apr 10, 2003 1:45 pm
by torpedo51
I think you are experiencing your browser's ability to cache what was on the page, and not a session "storing" your form element values (unless you explicity saved the values to session variables yourself?).

You need to decide whether you want to use the GET or POST method to move your values from page1 to page2. As a rule of thumb... use GET when navigating around your site, and use POST when the values are going to to be written to your database.

When you use POST, you will not really be able to hit the 'back' button.. at least not without getting a warning from your browser that, "this page was created using [POST] values which may no longer be available, do you want to reload the page anyway?"...

Hope this gets you pointed in the right direction.

Posted: Thu Apr 10, 2003 4:33 pm
by leebo
I am using post but dont get any errors when hiting the back button ! I have tried GET but doesn`t seem to work at all ! I'm confused 8O :!:

Posted: Thu Apr 10, 2003 11:14 pm
by bionicdonkey
if you go back in your browsers history to a page which as hadform data submitted and the POST data is still set, you should get an error stating that the page has expired. the only way to get the data back in the form would be to print the stored values back into the form.