Jump to content


Photo

Mysql Result Array Stored In $_SESSION Variable Disappearing


  • Please log in to reply
5 replies to this topic

#1 skyrice

skyrice
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 September 2006 - 06:26 PM

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

#2 skyrice

skyrice
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 September 2006 - 06:44 PM

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

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 25 September 2006 - 06:46 PM

I think that session_write_close() maybe the answer to your problems.

Let us know if that fixes it..

Good luck,
Tom

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#4 skyrice

skyrice
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 25 September 2006 - 06:59 PM

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?

#5 skyrice

skyrice
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 26 September 2006 - 06:32 PM

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

:-\

#6 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 26 September 2006 - 07:55 PM

You'll be glad to see PHP6 then :) (removing register_globals)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users