lucavilla
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.
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.
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?
Do you know a solution described in less than 1 page?
Hi,
This simple example will help you:
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';
?>
what happen tested or what >?
ASKER
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']=$_PO ST['name'] ;
?>
Use this in session1.php:
<?php
session_start();
$_SESSION['userName']=$_PO
?>
ASKER
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?
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']=$_GE T['name'];
?>
What you did try?
Please send me the code.
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']=$_GE
?>
What you did try?
Please send me the code.
ASKER
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't have time to test it but I think that it is what I will need. Thanks!
Look at this:
http://in2.php.net/session
http://www.w3schools.com/PHP/php_sessions.asp
http://www.tizag.com/phpT/phpsessions.php
This wil help you.
Regards