index.php上的意外令牌错误:1

时间:2015-02-02 17:55:13

标签: javascript php jquery ajax json

我有一个普通用户的2个登录模式和一个超级用户的登录模式...我正在用jquery监听按钮点击,用户一个正常工作但另一个它给了我一个错误:意外的令牌索引.PHP:1。我检查了分号,但没问题。



function login(){
    $("#btnUserLogin").click(function(e){
        var user = $('#boxUserUsername').val(),
            pass = $('#boxUserPassword').val(),
            feedback = $('#userFeedback');

        $.post("/ajax/login.php", {username: user, password: pass, table: 'users'}, function(data){
            var obj = JSON.parse(data);
            if(obj.type == 'err'){
                feedback.html(obj.content);
            }else{
               feedback.html(obj.content);
            }
        });
        e.preventDefault();
    });



    $("#btnModelLogin").click(function(e){
        var user = $('#boxModelUsername').val(),
            pass = $('#boxModelPassword').val(),
            feedback = $('#modelFeedback');

        $.post("/ajax/login.php", {username: user, password: pass, table: 'models'}, function(data){
            var obj = JSON.parse(data);
            if(obj.type == 'err'){
                feedback.html(obj.content);
            }else{
                feedback.html(obj.content);
            }
        });
        e.preventDefault();
    });


}

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<?php
require '../system/core.php';
if(isset($_POST['username']) && isset($_POST['password'])){
    $user = $_POST['username'];
    $pass = $_POST['password'];
    $tbl = $_POST['table'];


    $sql = "SELECT * FROM $tbl WHERE username='$user' AND active='Yes'LIMIT 1";
    $rows = $dbc->rows($sql);

    $feedback=array();

    if($rows != 0){
        $query = $dbc->query($sql);
        $row = $dbc->fetch($query);

        if($user == $row['username'] && sha1($pass) == $row['password']){

            //Store data in session
            $_SESSION['usr'] = new user($row);

            if($tbl == 'users'){
                $links = '
                <a href="/index.php?page=live"><i class="fa fa-video-camera"></i> Live Models</a> |
                <a href="/index.php?page=chat"><i class="fa fa-comments"></i> Chat</a> |
                <a href="/index.php?page=profile"><i class="fa fa-user"></i> Profile</a> | ';
            }else{
                $links = '
                <a href="/index.php?page=live"><i class="fa fa-video-camera"></i> Live Models</a> |
                <a href="/index.php?page=livechat"><i class="fa fa-comments"></i> Chat</a> |
                <a href="/index.php?page=profile"><i class="fa fa-user"></i> Profile</a> | ';
            }


            $feedback = prepare('succ', succ($links));
            echo json_encode($feedback);
        }else {
            $feedback = prepare("err", err("Username or Password is wrong."));
            echo json_encode($feedback);
        }

    }
    else{
        $feedback = prepare("err", err("This user doesn't exists or is not activated"));
        echo json_encode($feedback);
    }


}

function prepare($type, $msg){
    return array('type' => $type, 'content' => $msg);
}

function succ($msg){
    return '<p class="text-success"><i class="fa fa-check-circle"></i> <strong>Access Granted!</strong> '.$msg.'</p>';
}
function err($msg){
    return '<p class="text-danger"><i class="fa fa-times-circle"></i> <strong>Access Denied!</strong> '.$msg.'</p>';
}
?>
&#13;
&#13;
&#13;

0 个答案:

没有答案