Jump to content

Mysql Result Array Stored In $_SESSION Variable Disappearing


skyrice

Recommended Posts

Hi there, I'm new here. Anyhow, here's my dilemma:

<?php

  session_start();

  include 'database.inc';

  $query = mysql_query("SELECT * FROM `table`");

  $_SESSION['mysql_result_array'] = mysql_fetch_assoc($query);

  print_r($_SESSION['mysql_result_array']);

  /* This will print out:

      Array (
        [key] => value
        [key] => value
        [key] => value
      )

      As I would expect it to. */

?>

Now guess what happens when I get to another page and do this:

<?php

  session_start();

  print_r($_SESSION['mysql_result_array']);

  /* This prints out simply: Resource id #3 */

?>

I've tried even copying the array to a session variable key by key and it still gets destroyed when I move off the page. The reason I need this array in a session variable is because the next page is going to clear the data from the table, but I still need the data that used to be there in order to fill in some forms.

The session variable is perfectly set to the right array when I'm on the page, and then when you move off of that page it gets destroyed. This is so frustrating... Nothing is touching the array btw...
Link to comment
Share on other sites

Just for fun I ran the basic concept code that I originally posted and it worked fine. I then went and rechecked to make sure that absolutely nothing was messing with my session variables and confirmed it; it's not hard to see. There are only 3 references to $_SESSION between both scripts. I don't see how this is happening... =(
Link to comment
Share on other sites

Stuck that right underneath the $_SESSION variable assignment, then did print_r to make sure the right information was stored in the variable. Also did session_write_close() immediately after session_start() on the next page; same result. =(

How is the variable changing when nothing is changing it?
Link to comment
Share on other sites

I finally figured it out today. The people at my work have REGISTER_GLOBALS turned on. The session variable I was using has the same name as a non-session variable that is being assigned within the script and apparently it overwrites the $_SESSION variable of the same name as well. I didn't know that, nor did I know that REGISTER_GLOBALS was on...

Bunch of bums over here...

:-\
Link to comment
Share on other sites

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.