-4

所以我已经受够了这个任务,我仍然试图让这个登录页面真正登录,它应该是一个使用 $_SERVER['PHP_SELF'] 的自我引用登录页面,但它仍然不会做任何事情

<center>
<h2>Please log in</h2>
<p>Enter your login ID and password to connect to this system<br/>
</p>
<form name="Input" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table border="1" bgcolor="black" cellpadding="10" >
<tr>
    <td><strong>Username:</strong></td>
    <td><input type="text" name="login" value="" size="20" placeholder="Username" /></td>
</tr>
<tr>
    <td><strong>Password:</strong></td>
    <td><input type="password" name="password" value="" size="20" placeholder="**********"/></td>
</tr>
</table>
<table border="0" cellspacing="15" >
<tr>
    <td><input type="submit" value = "Login" /></td>

    <td><input type="reset" value = "Reset" /></td>
</tr>
</table>
</form>
<p>
Please wait after pressing <strong>Log in</strong>
while we retrieve your records from our database.<br/>
<em>(This may take a few moments)</em>
</p>
<hr/>
</center>
</body>
</html>

<?php   //embed in a page with a two input box (named id and pass) form
    require "functions.php";
    $login = $_POST['id'];
    $password = $_POST['password'];
    $conn = db_connect();
    $sql = "SELECT first_name, last_name, email_address, last_access FROM   users WHERE id = '".$login."' AND password= '".$password."'";
    $results = pg_query($conn, $sql);
    if(pg_num_rows($results)){  //not zero means something was found
//user found, use pg_fetch_result to pull user specific info to displa
    }else{
        //user not found, check for just login id
        $sql = "SELECT * FROM  users WHERE id = '".$login."'";
        $results = pg_query($conn, $sql);
         if(!pg_num_rows($results)){  //user not found, empty $login to unstick it
            $login = ""; //when echo’’ed in the form
        }
    }

这是我已经拥有的代码

这是我老师在课堂上给的代码,但它仍然不起作用

我也不知道把欢迎信息放在哪里或如何让它显示出来。

我试过用欢迎消息制作一个welcome.php 文件,但它仍然不起作用

我只是想念一些东西

(另外,如果你选择评论不要粗鲁,我很挣扎)

谢谢

?>

4

1 回答 1

3

在您的 PHP 代码中,您试图从中获取用户名,$_POST['Id']但实际上您的字段名称是$_POST['login']

正确更改字段名称,我也建议您error_reporting()在开发环境中使用,这将有助于您调试。

其次,不要保存明文密码,始终加密您的密码。

您的代码对 SQL 注入开放,以防止使用 PDO。

还有一个建议,如果提交了表单,请运行您的 PHP 脚本,或者您可以使用

if(count($_POST) > 0){
   //execute code
}

最后一个调试建议,当您正在使用<form>并且您认为它不起作用时,您必须使用以下方法检查是否获取输入:

print_r($_POST) // POST / GET

这将帮助您了解正在发生的事情。

于 2019-03-30T19:44:24.783 回答