Page 1 of 1

Problem with sessions

Posted: Tue Jan 29, 2008 12:21 pm
by QbertsBrother
i am having a problem setting session variables. i cant seem to figure out why. on one page i can echo the session variable and then on the next page i cant. i do have the session_start on each page.

what i am trying to do is set a variable with a value from the database. on the page that makes the query i can do this:

Code: Select all

 
    $data_query = mysql_query("SELECT id, dist FROM `" . DB_DATABASE . "`.`" . TBL_TMP . "` WHERE uid = '" . $uid . "' ORDER BY dist, name limit 1");
    $total_rows = mysql_num_rows($data_query);
    $remain = $total_rows%$num_per_row;
    while($data = mysql_fetch_assoc($data_query)) {
      
      $store = $res[$data['id']];
      $_SESSION['instate'] = $store['state'];
      echo "You live in " .$_SESSION['instate'];
}

and it echos the value of the state.

then on another page i want to do this and it does not work.

Code: Select all

 
if (isset($_SESSION['instate'])){
echo "i know you live in ". $_SESSION['instate']."<br/>".Print_r ($_SESSION);
}
else {
echo "enter your zip code ". session_id() ."<br/>state: ".$_SESSION['instate']."<br/>".Print_r ($_SESSION);
}
 
i get a session id and what not and here is what i see on the page that does not work:

Array ( ) enter your zip code 52e355bd3e5c8d33618de8c9fb65f3fc
state:
1

also if i do this on any page it carries the value from page to page. but i need the value to come from the database

Code: Select all

$_SESSION['instate'] = 'MN';
any help would be great thanks.

Re: Problem with sessions

Posted: Tue Jan 29, 2008 12:51 pm
by QbertsBrother
so i think it has to do with my session id. when i can view the value of $_SESSION[instate] the session_id is different than when i cannot view the value.

does anyone know why i am getting 2 different id's?

Re: Problem with sessions

Posted: Tue Jan 29, 2008 2:06 pm
by QbertsBrother
never mind i figured it out

thanks