www.webdeveloper.com
Results 1 to 6 of 6

Thread: Session Variable Resetting

  1. #1
    Join Date
    Apr 2004
    Posts
    12

    Session Variable Resetting

    Hello all,

    I have a php file called process.php that sets a session variable, namely $_SESSION['transtype']. This page also contains a form that is submitted to final.php.

    If I echo the value of $_SESSION['transtype'] at the end of the process.php file, it displays the correct value. However, in final.php, it is no longer set.

    In final.php I have the following snippet of code. The output of this page is "Not set." Why is the value of 'transtype' being lost between these 2 pages?

    <?
    session_start();

    $itemID = $_POST['item'];
    $numItems = $_POST['numItems'];

    if (isset($_SESSION['transtype']))
    echo $_SESSION['transtype'];
    else
    echo "Not set.";
    ?>

    Thx.

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    What does the code look like in your login page? The relevant part, anyway.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    Apr 2004
    Posts
    12
    Here is the code from process.php where transtype gets set correctly:

    <form method='post' action='final.php' name='order' onSubmit='return validateForm();'>
    <?
    session_start();

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

    if (isset($_POST['insert']))
    $_SESSION['transtype'] = "insert";
    elseif (isset($_POST['update']))
    $_SESSION['transtype'] = "update";
    elseif (isset($_POST['delete']))
    $_SESSION['transtype'] = "delete";

    Do you need to see more?

  4. #4
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    The session_start() function should throw an error, because you have output data to the browser before starting the session. Try putting session_start() at the beginning of the document, before you put any HTML code.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  5. #5
    Join Date
    Apr 2004
    Posts
    12
    Thanks so much for your help. That took care of it. I never would have figured that out on my own.

    Thanks again!

  6. #6
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Happy to help.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles