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

  • SEARCH
  • Home
  • 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 8667137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:53:48+00:00 2026-06-12T17:53:48+00:00

Hello i have a big problem .. I’m creating a user login site but

  • 0

Hello i have a big problem .. I’m creating a user login site but the problem is that if i have 2 or more users in database and if i try to log in with my 2nd user’s credentials it only gives me the 1st users info . Any help would be appreciate it.

Login.php

include '../init/init.php';

if (empty($_POST) === false) {
    // ...
    $username = $_POST['log_username'];
    $password = $_POST['log_password'];

    $login = login($username, $password);
    if ($login === false){
        die(msg1(0, 'Password is incorrect.'));
    }else{
        $_SESSION['id'] = $login;
        die(msg1(1,"members.php"));
        exit();
    }
}

users.php (I have all my user functions here)

    <?php

// ...
function user_id_from_username($username) {
    $username = sanitize($username);
    $query_user_id = mysql_query("SELECT (`id`) FROM `users` WHERE `username` = '$username'");
    return mysql_result($query_user_id, 0, 'id');
}

function login($username, $password) {
    $id = user_id_from_username($username);

    $username = sanitize($username);
    $password = md5($password);

    $query_login = mysql_query("SELECT COUNT(`id`) FROM `users` WHERE `username` = '$username' AND `password` = '$password'");
    return (mysql_result($query_login, 0) == 1) ? $id : false;

}
?>

And this shows the profile after login:

// ...
if (logged_in() === true){ 
  $session_user_id = $_SESSION['id']; 
  $sql = mysql_query("SELECT * FROM users"); 
  $id = 'id'; 
  $username = 'username'; 
  $rows = mysql_fetch_assoc($sql); 
}
$errors = array();

// show profile based on $rows
  • 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-06-12T17:53:49+00:00Added an answer on June 12, 2026 at 5:53 pm

    Judging from the code in the comments section I would advice changing the code to:

    $session_user_id = $_SESSION['id']; 
    $sql = mysql_query("SELECT * FROM users WHERE `id`='$session_user_id'"); 
    

    I’m going to assume that you sanitized $_SESSION['id'] beforehand.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So hello everyone I have a big problem right now with a button that
Hello I have a little big problem in JavaFX application with terminating java process
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I have next function, what always return null as result, but service calling
hello I have my code that connects to my ftp server $conn_id = ftp_connect($ftp_server);
Hello I have a datatable that I would like to filter with a single
hello i have just start using Raphael but i'm very confused in the following
I have a big problem (even my server's admin seems to have some difficulties
I have a big fat query that's written dynamically to integrate some data. Basically
I've got a big project written in PHP and Javascript. The problem is that

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.