Jump to content

Archived

This topic is now archived and is closed to further replies.

skyrice

Mysql Result Array Stored In $_SESSION Variable Disappearing

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...

Share this post


Link to post
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... =(

Share this post


Link to post
Share on other sites
I think that [url=http://us3.php.net/manual/en/function.session-write-close.php]session_write_close()[/url] maybe the answer to your problems.

Let us know if that fixes it..

Good luck,
Tom

Share this post


Link to post
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?

Share this post


Link to post
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...

:-\

Share this post


Link to post
Share on other sites
You'll be glad to see PHP6 then :) (removing register_globals)

Share this post


Link to post
Share on other sites

×

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.