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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:24:35+00:00 2026-06-02T08:24:35+00:00

I am trying to create a simple login credentials checker (with session variables). this

  • 0

I am trying to create a simple login credentials checker (with session variables).

this is what i have so far:

<?php
include("dbconnect.php");
$u_name = mysql_real_escape_string($_POST['uname']);
$p_word = mysql_real_escape_string($_POST['pword']);
# *** querying all records ***
$query = mysql_query("SELECT valid_username, valid_password FROM notes_users");
while($rst = mysql_fetch_array($query)) {

//echo $rst[valid_username] . ", ";
//echo $u_name . " || ";
//echo ($rst[valid_username] == $u_name) . " || ";
//echo $rst[valid_password] . ", ";
//echo $p_word . " || ";
//echo ($rst[valid_password] == $p_word) . " || ";
//echo (($rst[valid_username] == $u_name) AND ($rst[valid_password] == $p_word));
//echo "<br/>";

if (($rst[valid_username] == $u_name) AND ($rst[valid_password] == $p_word)) {
    session_start();
    $_SESSION['login'] = "1";
    header('Location: main.php') ;
} else {
    session_start();
    $_SESSION['login'] = '';
    header('Location: badlogin.php') ;
}


}

?>

here is the issue: If the MySQL table has more than one user in it’s list, the check breaks. only the last-entered user in the table has access granted. anyone above the last user entered gets bumped to the incorrect login screen- even when the credentials are correct. why is this happening? can anyone suggest a code fix or better code to implement this login check?

edit: the comment code tests to see if the credentials supplied match those on record. that part of the script works fine.

problem solved! thank you all. for anyone who sees this in the future, definitely encrypt your passwords, mine are plain text because this is a local test application and wont even see an upload to the net.

  • 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-02T08:24:38+00:00Added an answer on June 2, 2026 at 8:24 am

    There is no need to loop through all your user records. Imagine if you would have a database with 1000000 users, you will only need to try fetching the record that corresponds to the supplied username and password. Update your query to something like this:

    $query = mysql_query("SELECT * FROM notes_users 
                          WHERE 
                          valid_password = '$p_word' && 
                          valid_username = '$u_name'");
    

    Then you would do something like:

    if (($row = mysql_fetch_array($query)) {
       // valid user
    } else {
       // invalid password or username
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a simple username/password login screen. I have the layout done,
I'm trying to create a simple login system that will have the forms and
I'm trying to create a simple Spring 3 application and have the following files.
I am trying to create a simple login system. When I run the login
I'm trying to create a very simple login for only one or two users,
I' trying to create a simple login form where users should be able to
I am trying create system in which I can login from php and then
I have a working login form. I was just trying to do a simple
I am trying to create a simple login page in ASP.NET C# but am
So I'm trying to get a simple session based login working, and my sessions

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.