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}
    
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效