大家好,首先我要感谢你的时间,我要为大学做这个(网络服务器脚本单元p4)这是我的简单登录但无法启动并运行不断收到错误消息:注意:未定义的索引:第4行的C:\ xampp \ htdocs \ index.php中的用户名
这是我的代码:
<?php
session_start();
if($_POST["username"]) {
$dbUsname = "Stephen";
$dbPassword = "Password123";
$uid = "0001";
$usname = strip_tags($_POST["username"]);
$pass = strip_tags($_POST["password"]);
if (username == $dbUsname && $pass == $dbPassword) {
$_SESSION["username"] = $usname;
$_SESSION["id"] = $uid;
header("Location; user.php");
} else {
echo"<h2>UH OH Oh no you didnt your password was incorrect.
<br> /> Enter that again.</h2>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Basic Login System</title>
<style type="text/css">
html {
font-family: Verdano, Genevo, sans-serif;
}
h1{
font-size: 24px;
text-align: center;
}
#wrapper {
position: absolute;
width: 100px;
top: 30%;
margin-top: -50%;
}
#form {
margin: auto;
width: 200px;
height: 100px
}
</style>
</head>
<body>
<div id="wrapper">
<h1>Login</h1>
<form id="form" action="index.php" method="post" enctype="multiport/form-data">
Username: <input type="text" name="username" /> <br> />
Password: <input type="password" name="password" /> />
<input type="submit" value="Login" name="Submit" />
</form>
</body>
</html>
答案 0 :(得分:0)
$ _ POST可能没有任何名为“name”的索引。使用isset($ _ POST [“name”])来检查索引是否存在。