0
I’m having a problem returning an authentication message on a login page. Specifically and where it checks 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 "invalid password" error. The problem is that it returns invalid user and invalid password in the same condition. I’ve tried a lot of ways there on Isis and if it always happens the same thing in other ways I’ve tried.
Where did I go wrong?
Where the 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";
}
}
apparently there is nothing wrong with your condition, the error may be at the time of taking values from the database, use the
echo
to write hissql
on screen and place to rotate on SGBD. see if it returns any value.– Brumazzi DB