Hi - 2nd question.
Regarding variables created by forms and stored in sessions.
Lets say page1.php contains a form, which is posted to page2.php.
page2.php session_registers the input so it can be used in later pages, it also displays some of the data.
The problem comes when the user gets to page2, clicks "Back" on browser, re-enters data, and re-submits. I see the old data in page2.
How do you avoid this, and get the new data?
Thanks,
Tony
Form variables and sessions
Moderator: General Moderators
Page1:
Page2:
Hope that helps ya, I had a similar problem myself a few months back, I would also advise ya to take a good look at http://www.php.net/manual/en/ref.session.php
PhIrUs
Code: Select all
<form action="page2.php" method="post">
<input type="text" name="name" size="30" value="<?php echo $_SESSIONї'name']?>">
<input type="text" name="age" size="30" value="<?php echo $_SESSIONї'age']?>">
<input type="submit" name="submit" value="Continue">
</form>Code: Select all
<?php
session_start();
$_SESSIONї'name'] = $_POSTї'name'];
$_SESSIONї'age'] = $_POSTї'age'];
echo('<a href="page1.php">Go Back</a>');
?>PhIrUs
What is it you're trying to do? I wouldn't use sessions to carry form variables accorss pages, I use $HTTP_POST|GET_VARS. Using sessions can create problems, as you experienced yourself. The session variable is already set, so if you go back to the previous page and continue the session, the registered variable is still there, unless you unset it. Here's what I do:
I put that under the form tag on each page I am using in the form process. That way, the form variables are still there, and they're not registered as a session variable, so they're automatically reset in the $HTTP_POST_VARS array.
hope that helps
Code: Select all
if ($HTTP_POST_VARS)
{
while (list($lvar, $lvalue) = each($HTTP_POST_VARS))
{
echo "
<input type=hidden name="$lvar" value="$lvalue">
";
}
}hope that helps