I made a login system with ajax and php in it I pass the login and the password that are in the bank but I wanted to know what is wrong with my code because whenever I try to login to the site with a valid login it falls on my false status and it appears that I can not redirect. I gave an alert in the ajax return that shows the result of the php page and this is correct when I type the correct data it brings me in an alert that it was possible to connect what I need to do for my ajax not to fall in the false condition of my if ? I'm not going to post php because I only tested in php and it worked perfectly the problem is in ajax
code:
$("#logar").click(function(){
var email = $("#email").val(),
senha = $("#senha").val();
if(!senha){
$('[data-toggle="tooltip"]').tooltip();
$('#senha').tooltip('hide');
$(".tooltip").show();
$("#senha").focus();
return;
}
$.ajax("../sys/logaradm.php",{
type: "POST",
data: {'usuario':email, 'senha':senha}
}).done(function(r){
alert(r);
if(r==1){
alertify.success("Acesso concedido redirecionando...");
setTimeout("document.location = 'administracao.php'",2500);
}else{
alertify.error("Usúario ou senha informados nao existem!");
}
}).fail(function(){
alertify.error("Ocorreu um erro durante a operacao!")
});
});
php code:
session_start();
require "conexao.php";
$usuario = trim(@$_POST['usuario']);
$senha = trim(@$_POST['senha']);
$sql_acesso = mysqli_query($mysqli, "SELECT * FROM adm WHERE email = '$usuario' AND senha = '$senha' ");
if(mysqli_num_rows($sql_acesso) == 1 ){
$_SESSION['usuarioSession'] = $usuario;
$_SESSION['logadoadm']= true;
//$_SESSION['senhaSession'] = $senha;
echo "
<script type=\"text/javascript\">
alert(\"Login efetuado com sucesso!\");
window.location='administracao.php';
</script>";
}
else{
echo "
<script type=\"text/javascript\">
alert(\"Usuario ou senha informado esta incorreto!\");
window.location='../admin/admin.php';
</script>";
}
mysqli_close($mysqli);