Link to home
Start Free TrialLog in
Avatar of lucavilla
lucavillaFlag for Italy

asked on

remember form values using PHP session

I have a PHP webpage with a form with 6 values.  A submit button passes these 6 values as parameters via GET method to another PHP file.
After I press the browser "back" button, these 6 values appear empty.
How can I make them appear like they was the last time instead than empty?

Someone told me that there is a solution with cookie and a solution via PHP session. I'm interested in the solution via PHP session.
Avatar of shobinsun
shobinsun
Flag of India image

Avatar of lucavilla

ASKER

I looked at those pages but they seems complete guides to PHP session while I only need a once-in-a-life solution for a single webpage.
Do you know a solution described in less than 1 page?
Hi,

This simple example will help you:


<?php
session_start();
?>
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<form action='session1.php' method='post'>
<input type='text' name='name' value="<?php echo $_SESSION['userName'];?>">
<input type='submit' name='submit' value='Submit'>
</form>
</body>
</html>
 
session1.php:
 
<?php
session_start();
$_SESSION['userName']='shobin';
?>

Open in new window

what happen tested or what >?
I tested the shobinsun's code but it doesn't show the text that the user entered last time.  It always show the text "shobin". How can I make it show the text that the user entered last time?
Hi,

Use this in session1.php:

<?php
session_start();
$_SESSION['userName']=$_POST['name'];
?>
beautiful, it works!
but it doesn't work if I choose the GET method.
I need necessarily to use the GET method because I want to show the 6 parameters in the URL.
How can I make it work with the GET method?
Hi,

I am using this:

<?php
session_start();
?>
<html>
<head>
<title>Simple HTML Form</title>
</head>
<body>
<form action='session1.php' method='get'>
<input type='text' name='name' value="<?php echo $_SESSION['userName'];?>">
<input type='submit' name='submit' value='Submit'>
</form>
</body>
</html>

<?php
session_start();
$_SESSION['userName']=$_GET['name'];
?>


What you did try?

Please send me the code.
I should apply it here: http://alturl.com/74oj

It should remember the six entered values after the user submit them to get the results page and come back to the homepage.
 
ASKER CERTIFIED SOLUTION
Avatar of shobinsun
shobinsun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I didn't have time to test it but I think that it is what I will need. Thanks!