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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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