Forum Moderators: coopster
Even if I remove the value='$test' in the input tag, I'm still locked into my previous entry. Is this something so ridiculously simple?
Thx
Sam
<?php
session_start();
if(isset($submit_button)){
$_SESSION["var"] = $var;
echo "Var = $var";
exit;
}
?>
<html><head>
<title>Test</title>
</head>
<body>
<?php
echo "<form method=\"post\" name=\"form\" action=\"{$_SERVER['PHP_SELF']}\">";
echo "<input type=\"text\" name=\"var\" value=\"$var\">";
?>
<input type="submit" name="submit_button" value="Submit">
</form>
</body>
</html>
<?php
// you have to open the session to be able to modify or remove it
session_start();
// to change a variable, just overwrite it
$_SESSION['size']='large';
//you can remove a single variable in the session
unset($_SESSION['shape']);
// or this would remove all the variables in the session, but not the session itself
session_unset();
// this would destroy the session variables
session_destroy();
?>
Below I've got a simple form using session variables. If I enter "1234" in this form, then go to the next page and come back OR refresh this page, no matter what I enter, the "1234" stays locked into the variable $var.
Even if I remove the value='$var' in the input tag, I'm still locked into my previous entry. Is this something so ridiculously simple?
Suppose I was creating a form asking for your credit card number. You enter the number, and then click on SUBMIT. The number gets sent to the merchant. The transaction fails due to a wrong credit card number. The user clicks on his BACK button and re-enters the correct number.
This is kind of what I'm trying to do. I'm using session variables for page to page continuity. In the above example, the user would never be able to change their number in my example above as it somehow got locked in with the original data.