alert(message) returns 一个空字符串

alert(message) returns an empty string

@Hanky 웃 Panky 已解决!

我正在实现登录功能。

javascript部分:

function login() {
    var n = $('#userl').val();
    var p = $('#passl').val();
    if ( n != "" && p != ""){
        $.post("functions.php",{userl: n, passl: p}).done(function(mesaj){
            if(mesaj  == "")
               alert("!!!!!!!!!!EMPTY STRING!!!!!");
            else
            alert(mesaj);
        });
    }
    else {
        alert("Enter name and/or passwort");
    }
};

function.php 中的函数看起来:

function login($nume,$parola)
{
    $sql = "SELECT id FROM `Users` WHERE nume ='".$nume."' ANY password = '".md5($parola)."'";
    $q = mysql_query($sql);
    if(!$q)
        die(json_encode(array("mesaj" => "Invalid")));
    else{
        $x = mysql_fetch_array($q);
        if (empty($x))
            die(json_encode(array('mesaj' => 'The user does not exist')));
        else {
        //    $user = new User($x['id']);
            session_start();
            $_SESSION['user_id'] = $x['id'];
            $_SESSION['loggedin'] = "yes";
            die(json_encode(array("mesaj"=>"you were logged")));
        }

        }
    //this part may be useless
    die(json_encode(array("mesaj"=>"you were not logged")));
}


if (isset($_POST['nume']) AND isset($_POST['parola']))
         login($_POST['nume'], $_POST['parola']);

问题是它一直提醒 EMPTY STRING,我认为它甚至无法从 php 访问我的登录功能...所以消息按原样返回:empty

  $.post("functions.php",{userl: n, passl: p})

比较
if (isset($_POST['nume']) AND isset($_POST['parola']))

并找出你的错误:)

您正在发送 user1pass1,而在 PHP 中您正在检查 numeparola,它们不明显存在