I am trying to figure out just what's wrong with a login script provided by my instructor. There's a case where it will return a message about a blank username and password, but that never seems to happen if the logic for a nonexistent username and password is left intact!
Here's the relevant code:
$uname = $POST['em'];
$pw = $POST['pw'];
if (($uname == "") || ($pw == ""))
{
myRedirect("myLogin1.php?msg=3");
}
.. set up a connection and query the db
if(mysql_num_rows($result) > 0) // they're in the db
{//valid user, create session vars, redirect!
$row = mysql_fetch_array($result);
$sCustomerID = trim($row["CustomerID"]);
$sFirstName = trim($row["FirstName"]);
$sLogged = "zhy5688fty"; //unique string in case of multiple customers on server
session_start();
session_register("sCustomerID","sFirstName","sLogged");
myRedirect("myTarget1.php");
}
if(mysql_num_rows($result) == 0)
{
myRedirect("myLogin1.php?msg=2");
}
This last part was originally just an else from the good login if, as you'd expect. However, if that's in place, you never get the redirect for the first condition of the username and password being blank. With the last check disabled, it behaves like you'd expect (though of course nothing happens if the username and pw are wrong.)
I have no idea what's going on. The thing does work, but I don't understand why it goes past the first redirection for the blank case.
Derek