Problem with sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
QbertsBrother
Forum Commoner
Posts: 58
Joined: Thu Oct 11, 2007 10:12 am

Problem with sessions

Post 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.
QbertsBrother
Forum Commoner
Posts: 58
Joined: Thu Oct 11, 2007 10:12 am

Re: Problem with sessions

Post 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?
QbertsBrother
Forum Commoner
Posts: 58
Joined: Thu Oct 11, 2007 10:12 am

Re: Problem with sessions

Post by QbertsBrother »

never mind i figured it out

thanks
Post Reply