Jump to content

Multiple $_SESSION Variables Issue


dmhall0

Recommended Posts

When a user logs into my site I was to store the user_name, user_role, and user_id in a session variable, then store this in a regular variable to make querying easier, but I am having issues with my code as its causing issues with my queries.

 


if (mysqli_num_rows($data) > 0) {
  //set sessions
    $row = mysqli_fetch_array($data);
    $_SESSION['username'] = $row['username'];
    $_SESSION['user_role'] = $row['role'];
    $_SESSION['user_id'] = $row['user_id'];
          
            
  //set variables
    $username = $_SESSION['username'];
    $user_role = $_SESSION['user_role'];
    $user_id = $_SESSION['user_id'];

}

 

Any ideas whats wrong?!

Thanks for the help!!

Link to comment
https://forums.phpfreaks.com/topic/262086-multiple-_session-variables-issue/
Share on other sites

tr something like this.

 

 

//looping all rows and setting it as a session
foreach($row as $key=>$value)
{
if(is_string($key)){ //if keys a string set session
$_SESSION[$key] = $value;
}

//echo out the session
echo $_SESSION['username']; //should output the session
}

Archived

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

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