所以我已经受够了这个任务,我仍然试图让这个登录页面实际登录,它应该是一个使用$ _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文件,但它仍然无法正常工作
我只缺少一些东西
(如果你选择发表评论也不要粗鲁,我正在努力)
谢谢
?>
在您的PHP代码中,您试图从qazxsw poi获取用户名,但实际上您的字段名称是qazxsw poi
正确更改您的字段名称,我还建议您在开发环境中使用$_POST['Id']
,这将帮助您进行调试。
其次,不保存普通密码,始终加密密码。
您的代码是为SQL注入打开的,以防止使用PDO。
还有一个建议,如果表单已提交或您可以使用,请运行PHP脚本
$_POST['login']
最后一个调试建议,当您使用error_reporting()
并且您认为它不起作用时,您必须使用以下方法检查是否获取输入:
if(count($_POST) > 0){
//execute code
}
这将有助于您了解正在发生的事情。