Validate PHP login

1

Well, I'm trying to log in to the little project and I'm having trouble if the $ login is correct go to the shopping.html if it is wrong, the wrong login or password appears.

$login = mysql_query("SELECT Nome, Password FROM tb_utilizador WHERE Nome ='$Nome' AND Password = '$Password'");

if ($login = TRUE ) {


    header('location: Compras.html');
} else {

    // falhou o login
    echo "<p>Utilizador ou password invalidos. <a href=\"index.html\">Tente novamente</a></p>";
}

}

    
asked by anonymous 02.06.2016 / 13:26

1 answer

2

Try this form:

$login = mysql_query("SELECT Nome, Password FROM tb_utilizador WHERE Nome ='$Nome' AND Password = '$Password'");

$res = mysql_fetch_row($login);
   if($res)
   {
     header('location:compras.html');
   }

   else
   {
     header('location:error.php');
   }

error.php will be the page where you will provide a message stating that the user and / or password are incorrect. In case this is not the page you only change the displayed name. I just put error.php as an example for error page

    
02.06.2016 / 13:35