How to keep $_SESSION until submit form?

Total Post:159

 1330  View(s)
Rate this:

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 has the session_start(); so every page has this called

  1. Post:89

    Re: How to keep $_SESSION until submit form?

    <?php session_start(); ?>
    function form($type)
            {   return "<form action=\"\" method=\"POST\" >
                         <input type=\"text\" name=\"next\" />
                         <input type=\"submit\" name=\"$type\" />
                         </form> ";  } 
        function module(){
            echo form('one'); 
            if(isset($_POST['next']) && !empty($_POST['next']))
            $_SESSION['title'] =  $_POST['next'];
            }else {echo "post is empty";}
            }else {echo "Please fill the field";}
        }   function module2(){
            echo form('two'); 
            if(isset($_POST['next']) && !empty($_POST['next']))
            $_SESSION['content'] =  $_POST['next'];
            }else {echo "post is empty";}
            }else {echo "Please fill the field";}
        function module3(){
            echo form('three'); 
            if(isset($_POST['next']) && !empty($_POST['next']))
            $_SESSION['category'] =  $_POST['next'];
            }else {echo "post is empty";}
            }else {echo "Please fill the field";}
        echo module(); }
        else if(isset($_SESSION['title']) && !isset($_SESSION['content']))
        echo module2(); } else if(isset($_SESSION['content']) && !isset($_SESSION['category'])){
        echo module3();
        // you can delete, below this line. 
            echo "<div style=\"width:1000px; align:left; border:1px dashed #darkblue; color: darkblue; font-size:14px;  \" />";
            function SessionChecker($type){ 
                if(isset($_SESSION[$type]) && !empty($_SESSION[$type]))
                    { echo "Session $type is set as <b>". $_SESSION[$type]."</b><br/>";} else {echo "Session '$type' is not set <br/>";}     }
                    echo SessionChecker('title');
                    echo SessionChecker('content');
                    echo SessionChecker('category');
            echo "</div>";

      Modified On Nov-01-2014 12:46:55 AM