Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP check password script wont work for more than one user
    primarykey
    data
    text
    <p>I am trying to create a simple login credentials checker (with session variables).</p> <p>this is what i have so far:</p> <pre><code>&lt;?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 "&lt;br/&gt;"; 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') ; } } ?&gt; </code></pre> <p>here is the issue: If the MySQL table has more than one user in it's list, the check breaks. only the <strong>last-entered user in the table</strong> 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?</p> <p>edit: the comment code tests to see if the credentials supplied match those on record. that part of the script works fine.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload