forum

Home / DeveloperSection / Forums / How to keep $_SESSION until submit form?

How to keep $_SESSION until submit form?

Samuel Fernandes208301-Nov-2014

Firstly thank you for reading this, I have a form it has 3 pages with data needed to be store from page 1 and page 2 and finally on page 3, then it gets sent to the database.

I use this on page 2 to store info from page 1 (assuming on page 1 of my form has session_start();)

$_SESSION['Name']= $_POST['Name']; 
$_SESSION['contactno']= $_POST['contactno'];
$_SESSION['surname']= $_POST['surname'];
$_SESSION['mobileno']= $_POST['mobileno'];

Then page 3 gets information from page 2 using this to keep the info.

 $_SESSION['addressline1']= $_POST['addressline1'];

 $_SESSION['addressline2']= $_POST['addressline2'];

 $_SESSION['addressline3']= $_POST['addressline3'];

 $_SESSION['email']= $_POST['email'];

 $_SESSION['customerType']= $_POST['customerType'];


It works to a point if I echo $_SESSION['email'] on page 3 it shows up BUT IF I echo any $_SESSION from page 2 on my final page it doesn't show up anything.

I've spent ages looking at storing sessions, but I can't seem to work it out.

To summerise:-

·         PAGE 1 Starts the session (session_start()) and user enters their Name, Number Surname and Mobile.

·         PAGE 2 Stores the information inputted by the user on Page 1 and users enter their address, email and select membership type.

·         PAGE 3 Stores the information inputted by the user on Page 2 and user selects payment method(no payment is taken as I just want to know how a member would like to pay ,so cheque or paypal)

·         PAGE 3 also has one piece of info which isn't stored as the page Submits all the information to the database.

Problem on PAGE 3 no data from PAGE 1 is displayed if I try to ECHO any info from PAGE 1 I get this error :- Notice: Undefined index: 

I have a main page called Default.php which includes this code:-

 if($_REQUEST['p']){ include('includes/'.$_REQUEST['p'].'.php');

all my pages then are called from this page which is in the following format

  default.php?p=addmember
  default.php?p=addmember-page2
  default.php?p=addmember-page3

default.php has the session_start(); so every page has this called


Updated on 01-Nov-2014

Can you answer this question?


Answer

1 Answers

Liked By