preserve value of session

Discussion in 'PHP' started by tirso, Jul 22, 2008.

  1. #1
    I have a lot of text boxes, check boxes, etc in a form which the user would fill-in and it will take 4 forms or pages. In every page after the user completed filling the forms, I got the value using session. How can I preserve the value that I could retrieve after the completion of all the 4 pages of forms and display it. I already tried to put it in array but when I called this array after the last page/form it was result nothing. Please see the code

    Please help me and advice

    Thanks


    Code after in every page.
    <?
    session_start();
    $arval = array();
    require_once("../include/session.php");
    reset ($_POST);
    while(list($key, $val) = each ($_POST))
        {
    		if ($val == "") 
    		  $val = "NULL";
    		$arVals[$key] = (get_magic_quotes_gpc()) ? $val : addslashes($val);
    ?>
    
    PHP:
    session.php
    <?
        $_SESSION['SESSION'] = true;
    	// setup a dummy array...
    	$arVals = array("monthdatebenifit"=>"", "daydatebenifit"=>"", "yeardatebenifit"=>"");
    ?>
    PHP:
    I call $arVals['monthdatebenifit'] end echo but no result.
     
    tirso, Jul 22, 2008 IP
  2. itcn

    itcn Well-Known Member

    Messages:
    795
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    118
    #2
    You're not assigning anything to the session, you're just using a regular array. Here's how you want to do it (in simplified code):

    
    <?php
    session_start(); 
    while(list($key, $val) = each ($_POST))
    ...
    $_SESSION[$key] = $val;
    ...
    ?>
    
    Code (markup):
    You can't just use any array with a session, you have to use the built-in $_SESSION variable.

    A tutorial on using PHP sessions: http://www.tizag.com/phpT/phpsessions.php
     
    itcn, Jul 23, 2008 IP
  3. lamborevijay

    lamborevijay Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You need to start the session on each of these 4 pages.

    there shld be session_start() at the top of each page.

    Regards.
     
    lamborevijay, Jul 23, 2008 IP
  4. tirso

    tirso Peon

    Messages:
    24
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks to both of you.

    Best regards,
    Tirso
     
    tirso, Jul 23, 2008 IP