views:

897

answers:

1

Hi,

I am totally new to coding and i would need some help regarding this question of mine. the question is that,

I have around 5 html pages.I am trying to walk the user through each phase and thats the reason i have diffent page for entering the info.Each html page has certain text fields.For ex

Page1:lastname,firstname,mi...
Page2:address,phone,city,state,zip
Page3:date of join,time of joining,person who referred you
Page4:insurance info,insurance number
Page5:directions to the place, and so on.

Now the thing is that, i need to store the field values using sessions in php.

Suppose the user goes from page 1 to page 2(after filling all the details), and then if he wants to visit page 1,he should have all the fields populated with the data which he sent before(these details can be changed now).I want to store all the fields in a PHP array and then store the array using sessions.

My question is that how do we set the value of the php variable to the Value in the Textbox(the textbox will have the value entered by the user) and how do i design the array, and store it in the session.

Also can i use the same session variables across all the pages,so that i could save all the details entered by one particular in the array(which is then stored in the session).

Any help is greatly appreciated.

+1  A: 

You can access the data passed to you in the $_GET and $_POST variables. eg

$lastname = $_POST['lastname'];

You can store the value away in a session like this...

session_start();  // call this once on your page
$_SESSION['lastname'] = $_POST['lastname'];

You could even do something like this...

// Store all the posted values in the session
$_SESSION['page1'] = $_POST;
rikh
thanks for the answer Rikh.I had one more question.can i store the variables from all the pages in this one session var
swathi
Yes. When you call session_start(), all the data stored in the session so far is recovered and is accessible from $_SESSION. It normally works by storing the data in a file on the server and using a cookie to find the correct bit of data on the next page view.
rikh
thanks a lot Rikh
swathi