Login with AJAX and PHP with database (Why is it going wrong?)

0

$(document).on("click","formlogin",function(evt)
{
     $.ajax({
         type:"GET",
         url:"http://localhost:8080/ProjetoXDK/appModelo/www/php/entrar.php",
         data:{
            var cpf =  $('#cpf').val(),
            var senha = $('#senha').val();
            },
         datatype:"json",
         sucess: function(data){
         if ('#cpf' == $cpf || '#senha' == $senha1){
             activate_page("#inicio"); 
             navigator.notification.alert("Bem Vindo");
         }else{
             navigator.notification.alert("CPF ou senha errados");
         }
      }
    });
   });
<div class="grid grid-pad urow uib_row_2 row-height-2" data-uib="layout/row" data-ver="0">
                <div id="loginResult" style="display:none;">
                </div>
                <form id="formlogin" name="formlogin" method="GET">
                    <div class="col uib_col_2 col-0" data-uib="layout/col" data-ver="0">
                        <div class="widget-container content-area vertical-col">
                            <div class="table-thing widget uib_w_4 d-margins" data-uib="twitter%20bootstrap/input" data-ver="1">
                                <label class="narrow-control"></label>
                                <input class="wide-control form-control default" onkeypress="this.value = FormataCPF(event)" onpaste="return false;" name="cpf" id="cpf" type="text" placeholder="CPF" maxlength="14">
                            </div>
                            <div class="table-thing widget uib_w_5 d-margins" data-uib="twitter%20bootstrap/input" data-ver="1">
                                <label class="narrow-control"></label>
                                <input class="wide-control form-control default" name="senha" id="senha" type="password" placeholder="Senha">
                            </div>
                            <button class="btn widget uib_w_3 d-margins as btn-default" data-uib="twitter%20bootstrap/button" data-ver="1" id="btnEntrar">Entrar</button><span class="uib_shim"></span>
                            <div id="loginResult" style="display:none;">
                            </div>
                        </div>
                    </div><span class="uib_shim"></span>
                </form>
            </div>

<?php
session_start();
$uCpf = $_POST['cpf'];
$pSenha = md5($_POST['senha']);
$qry = "SELECT * FROM usuarios WHERE cpf='".$uCpf."' AND senha='".$pSenha."' AND status='active'";
$res = mysql_query($qry);
$num_row = mysql_num_rows($res);
$row=mysql_fetch_assoc($res);
if( $num_row == 1 ) {
	echo 'true';
	$_SESSION['uCpf'] = $row['cpf'];
	$_SESSION['pSemha'] = $row['senha'];
	}
else {
	echo 'false';
}

?>

    
asked by anonymous 22.10.2017 / 20:29

1 answer

2

You should declare properties of the object data and not declare variables within the object.

Mute

 data:{
     var cpf =  $('#cpf').val(),
     var senha = $('#senha').val();
},

for

 data:{
    cpf:  $('#cpf').val(),
    senha: $('#senha').val();
},

Moreover, the if ('#cpf' == $cpf || '#senha' == $senha1){ line does not make sense, it should use the PHP response which in this case is only true or false .

    
22.10.2017 / 20:30