weixin_33691817 2016-03-14 03:18 采纳率: 0%
浏览 13

ajax登录错误,无法检查

I have problem, I can't check username and password, can you help me?

login.php:

<form class="login-form" method="post" name="loginform" action="">
    <div class="title-section">
        <h1><span>Login</span></h1>
    </div>
    <p>Welcome! Login in to your account</p>
    <label for="user_login">Username or email address<span>*</span>
    </label>
    <input type="text" name="log" id="user_login">
    <label for="user_pass">Password<span>*</span>
    </label>
    <input name="pwd" id="user_pass" type="password">
    <div id="error"></div>
    <button type="submit" name="submit-login" id="submit-login"> <i class="fa fa-arrow-circle-right"></i> Login </button>
</form>

model.php;

<?php 
ob_start();
session_start(); 
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
?>
<?php
global $pdo;
session_start();

if(isset($_POST['submit-login'])) {
    $user_email = trim($_POST['log']);
    $user_password = trim($_POST['pwd']);

    try { 
        global $pdo;
        $stmt = $pdo->prepare("SELECT * FROM user WHERE username=:email");
        $stmt->execute(array(":email"=>$user_email));
        $row = $stmt->fetch(PDO::FETCH_ASSOC);
        $count = $stmt->rowCount();

        if($row['user_password']==$password){
            echo "ok"; // log in
            echo $_SESSION['user_session'] = $row['id_user'];
        }
        else {
            echo "email or password does not exist."; // wrong details 
        }
    }
    catch(PDOException $e){
        echo $e->getMessage();
    }
}
?>

ajax.js

$(document).ready(function(){
    $("#submit-login").click(function(){
        username=$("#user_login").val();
        password=$("#user_pass").val();

        $.ajax({
            type: "POST",
            url: "admin/module/admin/model/acc_model.php",
            data: "name="+username+"&pwd="+password,
            success: function(html){    
                if(html=='ok') {
                    window.location="profile.php";
                }
                else {
                    alert('Please, Error');
                }
            },
            beforeSend:function() {
                $("#error").html("<img src='http://www.chinesecio.com/templates/base/images/loading.gif' /> Loading...")
            }
        });

        return false;
    });
});
  • 写回答

2条回答 默认 最新

  • 10.24 2016-03-14 03:29
    关注

    I think that when you are sending data from your ajax request you are using different variable names and in your model.php you are using your form elements name. Please check into that

    data : {"name":username, "password ":password}
    
    评论

报告相同问题?