I'm having a problem with returning an authentication message on a login page. Specifically and where it verifies that the login and password field are checked as TRUE, if yes and the user does not contain in the database it will return "invalid user", if it contains the user and the password is wrong it should return the error of "invalid password ". The problem is that it returns invalid user and invalid password in the same condition. I have already tried several shapes there in the else and if the same thing always happens in other ways I tried.
Where did I go wrong?
Where inconsistency happens:
if ($login == TRUE && $senha == TRUE) {
$_SESSION['login']=$login;
unset ($_SESSION['senha']);
echo "Senha inválida";
}
if ($login == TRUE && $senha == TRUE) {
unset ($_SESSION['login']);
echo "Usúario inválido";
}
Full Validation:
session_start();
$login = $_POST['login']; $senha = $_POST['senha'];
$con = mysql_connect("localhost", "root", "") or die ("Sem conexão com o servidor");
$select = mysql_select_db("portal") or die("Sem acesso ao DB");
$result = mysql_query("SELECT * FROM 'USUARIO' WHERE 'NOME' = '$login' AND 'SENHA'= '$senha'");
if(mysql_num_rows ($result) > 0 ) {
$_SESSION['login'] = $login;
$_SESSION['senha'] = $senha;
header('location:editar-excluir.php');
}
else {
if ($login == FALSE && $senha == FALSE){
echo"Por favor preencha o nome do usuário e senha" ;
}
if ($login == FALSE && $senha == TRUE) {
echo "Por favor preencha o campo do usuário";
}
if ($login == TRUE && $senha == FALSE) {
echo "Por favor preencha o campo senha";
}
if ($login == TRUE && $senha == TRUE) {
$_SESSION['login']=$login;
unset ($_SESSION['senha']);
echo "Senha inválida";
}
if ($login == TRUE && $senha == TRUE) {
unset ($_SESSION['login']);
echo "Usúario inválido";
}
}