Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ajaxpost方法与php_Php_Ajax_Post_Login - Fatal编程技术网

ajaxpost方法与php

ajaxpost方法与php,php,ajax,post,login,Php,Ajax,Post,Login,总而言之,我在这里解释我的问题(据我所知,我没有找到任何有效的解决办法)。 我在这里链接我的文件: progetto.html <html> <head> <script type="text/javascript" src="funzioni.js"></script> <title>Pagina iniziale</title> </head> <body align='center

总而言之,我在这里解释我的问题(据我所知,我没有找到任何有效的解决办法)。 我在这里链接我的文件:

progetto.html

<html> 
<head> 
    <script type="text/javascript" src="funzioni.js"></script>
    <title>Pagina iniziale</title>
</head>
<body align='center'>
    <p>Gymnasium</p>
    <p>icona</p>
    <form id="ajaxForm" name="ajaxForm">
        <table align="center">
            <tr>
                <td><label>Utente</label></td>
                <td><input type="text" name="user" id="user" value="" /></td>
            </tr>
            <tr>
                <td><label>Password</label></td>
                <td><input type="password" name="password" id="password" value="" /></td>
            </tr>
        </table>
        <input type="button" id="submit" name="submit" value="Accedi" onclick='submitForm()' />
    </form>
    <div id="risultato"></div>
</body>
}

}

ajaxLogin.php

<?php
if (!isset($_POST["user"]) || !isset($_POST["password"])){
    die("Bad login");
}
$user = $_POST['user'];
$pwd = $_POST['password'];
if ( (($user == "angel") && ($pwd == "devil")) || (($user == "john") && ($pwd == "smith")) ){
    $response = "Benvenuto  " . $user;
    echo $response;
}

问题是我总是收到错误的登录消息,即使我使用了正确的用户和密码。 这是一个POST问题,我真的很难想出解决方案

这是您的数据:

var data = "utente=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;
这就是您要检查的内容:

if (!isset($_POST["user"]) || !isset($_POST["password"])){
您应该将
utete
更改为
user
,或者相反。在您的表单中,您也在使用
user
,因此我建议您在任何地方都使用它

因此:


@用户3184908不客气,如果解决了您的问题,请不要忘记将答案标记为已接受。
var data = "utente=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;
if (!isset($_POST["user"]) || !isset($_POST["password"])){
var data = "user=" + document.getElementById('user').value + "&password=" + document.getElementById('password').value;