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 9208345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:35:47+00:00 2026-06-18T00:35:47+00:00

As I described in my old posts, I’m upgrading my small project from MYSQL

  • 0

As I described in my old posts, I’m upgrading my “small” project from MYSQL into MYSQLi. I have successfully upgraded the whole project and I thought everything was working fine, untill I created new user.. The problem is that I can use which username I want and it will say if the data is not correct but when data is correct and login successfull no mater what username I use it always logins me as username with ID = 1.

Here’s my code:

Login:

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

    global $db_connect;

    $result = $db_connect->query("SELECT COUNT(id) FROM `members` WHERE `username` = '$username' AND `password` = '$password'");
    if (false === $result) {
        return false;
    }
    return ($result->num_rows == 1) ? $id : false;
}

User ID from USERNAME:

function user_id_from_username($username) {
    $username = sanitize($username);
    global $db_connect;

    $result = $db_connect->query("SELECT(id) FROM members WHERE username = '$username'");
    if (false === $result) {
        return false;
    }
    return ($result->num_rows == 1) ? true : false;
}

Any help would be appriciated, I tried out so many things, and were comparing all my MYSQLi with MYSQL files and still I can’t find any issue of this.

  • 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-18T00:35:49+00:00Added an answer on June 18, 2026 at 12:35 am
    return ($result->num_rows == 1) ? $id : false;
    

    will always return true, as you are counting the rows with SELECT COUNT(id), so you will always have one result

    Second thing, in user_id_from_username:

     return ($result->num_rows == 1) ? true : false;
    

    you return TRUE and not the user_id. Change it so you return the user id, and not true.

    true == 1, so thats why you always end up with userid 1.

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

Sidebar

Related Questions

I have the same problem as described in the posts listed below. That is,
I have an old post Re-Installing IPhone App From Inside The App That old
I have been tasked with updating a old project that I did not write.
I'm working on old code that relies heavily on the exception specifications behavior described
The CSS gradient is described here , but I have no idea how to
I have two tables described below. What I need is a single query that
In my current company, we have this decade old...let's call it a Hello World
I have written some C/C++ extension modules for PHP, using the 'old fashioned way'
... which I didn't feel like splitting into several question posts, since I guess,
I have an old python script that includes print commands. Sometimes I need to

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.