Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:35+00:00 2026-05-27T06:19:35+00:00

I have got a basic login script at the moment. When the user logs

  • 0

I have got a basic login script at the moment.

When the user logs in 2 variables are defined:

$_SESSION['user_id'] = $user['user_id'];
$_SESSION['username'] = $user['username'];

the index.php file has this

session_start();
if(array_key_exists('user_id', $_SESSION) && array_key_exists('username', $_SESSION)):

That is all fine, however once the session is started I would like to add more values from a database so I have this code here:

$res = mysql_query($sql);
$_SESSION = mysql_fetch_assoc($res);

When I do this it overrides the $_SESSION[‘user_id’] and $_SESSION[‘username’].
I tried this:

$_SESSION .= mysql_fetch_assoc($res);

but it didn’t work.

Does anyone have any ideas?

Thanks
peter

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:19:36+00:00Added an answer on May 27, 2026 at 6:19 am

    That’s because you’re setting the value of the variable $_SESSION to the return value of mysql_fetch_assoc($res);.

    What you want to do is something like $_SESSION['query_result'] = mysql_fetch_assoc($res). If you just want to add a single column of your database result to the session you would do it like this:

    $res = mysql_query($sql);
    $data = mysql_fetch_assoc($res);
    $_SESSION['myKey'] = $data['myKey'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very basic question - but I couldn't find an answer. I have got a
I have looked at Spring MVC a few times briefly, and got the basic
We have got loads of options for php + MySQL + Apache combo... Which
I have got a python script which is creating an ODBC connection. The ODBC
I have got some old sources written in Visual Basic. There are *.bas ,
I am implementing the huffman algorithm in C. I have got the basic functionality
I understand the basic user authentication, login, creating accounts, extending user model... I am
I am interested to learn about Eclipse RCP, I have got some basic knowledge,
Have got an NSString *str = @12345.6789 and want to find out if there
We have got a custom MembershipProvider in ASP.NET . Now there are 2 possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.