Jump to content

Recommended Posts

I'm having a problem, my code works fine when I run it on my localhost.  When I load it to the "live" server some session variables disappear.  I did a check a find that my localhost is running version 5.2.0 but the "live" server is running version 4.4.7.  Could this be my problem? Do the two version handle session variables differently?

 

Any guidance will be appreciated!

Page one has a dropdown menu to select a customer by name

 

if (!isset($_SESSION)) {

  session_start();

}

$cust_id = '';

 

This is the part of the code where $cust_id comes from

 

      <td><div align="left">

        <select name="cust_id" id="cust_id" class="textbackground">

          <option value="" <?php if (isset($error) && isset($_POST['cust_id']) == $cust_id) { echo 'selected="selected"';}

          elseif ($firstid == $cust_id) {echo "selected=\"selected\"";} ?>>          </option>

          <?php

          do { ?>

          <option value="<?php echo $row_getCust['customer_id']?>"<?php if (!(strcmp($row_getCust['customer_id'], $firstid)))

              {echo "selected=\"selected\"";} ?>>

            <?php echo $row_getCust['last_name']?> <?php echo $row_getCust['first_name']?> <?php echo $row_getCust['mi']?>

            </option>

          <?php

            } while ($row_getCust = mysql_fetch_assoc($getCust));

            $rows = mysql_num_rows($getCust);

            if($rows > 0) {

              mysql_data_seek($getCust, 0);

          $row_getGetCust = mysql_fetch_assoc($getCust);

          }?>

        </select>

      </div></td>

 

After customer is selected from the dropdown menu, I store $cust_id to session variable

 

if (!empty($_POST['cust_id'])) {

      $_SESSION['cust_id'] = $cust_id;

}

 

Now I go to another page to display that customer's info

 

if (!isset($_SESSION)) {

  session_start();

}

echo 'customer id =  ';

echo $_SESSION['cust_id'];

 

When I'm on the localhost the result is - customer id = 4

 

When I'm on the "live" server the result is - customer id =

 

The only thing I can say right now after looking at that is that you don't need to do this:

if (!isset($_SESSION)) {
  session_start();
}

 

session_start() creates a session or resumes the current one. Therefore, there's no need for any if statements. You say session_start() at the top of every page that you're using session variables on. At the very top. Before anything else. If there is a session, it resumes it. If not, it starts a new one.

 

The manual

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.