View Full Version : holding variables between pages
01-31-2007, 02:18 PM
I have a registration form, with quite a bit of validation, if something doesnt match, then the php script will throw up an error with a "click here to go back"
When the user goes back using their browser or following the link, the variables of username, password etc etc dissapear causing the user to re-type everything, how can I stop this?
01-31-2007, 03:08 PM
Either pass the variables with a query string or a cookie or session variable.
<input type="text" name="user" value="<?php echo $_GET['user'] ?>" />
On the "click here to go back" link you'd have-
<a href="url.php?user=<?php echo $_POST['user']; ?>">click here to go back</a>
Get it? Obviously you'd be best off doing it a bit more cleaner than that, but those are your options (query, cookie, session) and they're all similar to implement.
[edit:] If you really wanted, you *could* post them back as well with a bit of js.
01-31-2007, 03:27 PM
thanks for the fast reply!
The thing is, there is alot of information that will need to be moved around. The form uses "POST" to post to the next page, is there a way of transferring the data without the user knowing (without using sessions or cookies?) SOrry if you've already answered this :)
01-31-2007, 03:31 PM
Well, you can store the info somewhere.. But you're still going to need a way to associate that user with the data.. either sessions or a cookie..
01-31-2007, 03:47 PM
right ok thanks :)
Im sorry if this is really stupid, but when i post the information, I assign the information to the session like this:
$_SESSION['usernamestored'] = $_POST['username'];
and then on the first page (the one they entered the info on) I enter this:
echo('<input type="text" class="smallform" name="username" value="'.$_SESSION['usernamestored'].'" />');
but the input box appears blank?
01-31-2007, 03:52 PM
01-31-2007, 03:55 PM
Do you have a session_start(); php statement as the first thing on every page that references any $_SESSION variable?
01-31-2007, 04:04 PM
yeah, that's on the top of every page
01-31-2007, 04:07 PM
Well that just leaves it down the $_POST['var'] being empty.
01-31-2007, 04:41 PM
haha how stupid!
That was the problem! I managed to fix it now! thank you both very much :)
01-31-2007, 05:05 PM
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.