我在index.html页面中有这段代码
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Admin Panel</h2>
<FORM NAME ="form1" METHOD ="POST" ACTION = "login.php">
<INPUT TYPE = "TEXT" name="username">
<INPUT TYPE = "PASSWORD" name="password">
<INPUT TYPE = "Submit" NAME = "Submit1" VALUE = "Login">
</FORM>
</body>
</html>
和我的login.php文件中的代码
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
$adminUsername = "dushyant30suthar";
$adminPassword = "12345";
$enteredUsername = $_POST['username'];
$enteredPassword = $_POST['password'];
print ($enteredPassword);
if($enteredUsername == $adminUsername && $enteredPassword == $adminPassword)
{
print("Logged in");
print ($username);
}
else
{
print("Login Failed");
print ($enteredUsername);
print ($enteredPassword);
print ($adminUsername);
print ($adminPassword);
}
?>
</body>
</html>
当我尝试打印我从index.html获得的值时,它没有显示任何数据,但是我在login.php中修复的值正在显示。
答案 0 :(得分:1)
您的登录代码可以通过我正在测试的内容正常运行,但您仍然会在login.php
中出错:
if($enteredUsername == $adminUsername && $enteredPassword == $adminPassword)
{
print("Logged in");
print ($username);
}
在您向我们展示$username
的代码中,您可能希望将其更改为:
if($enteredUsername == $adminUsername && $enteredPassword == $adminPassword)
{
print("Logged in");
print ($enteredUsername);
}
答案 1 :(得分:-1)
以下是index.html的代码:
if (foo == nullptr)
将此代码用于<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h2>Admin Panel</h2>
<form name="form1" method="post" action="login.php">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" name="submit1" value="login">
</form>
</body>
</html>
文件,它正在运行:
login.php
我已经添加了一张支票,如果已经提交了必要的表格:
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<?php
$adminUsername = "dushyant30suthar";
$adminPassword = "12345";
if (isset($_POST['submit1'])) {
$enteredUsername = $_POST['username'];
$enteredPassword = $_POST['password'];
print ($enteredPassword);
if($enteredUsername == $adminUsername && $enteredPassword == $adminPassword)
{
print("Logged in");
print ($enteredUsername);
}
else
{
print("Login Failed");
print ($enteredUsername);
print ($enteredPassword);
print ($adminUsername);
print ($adminPassword);
}
}
?>
</body>
</html>
已修复:if (isset($_POST['submit1'])) {
未定义,我使用$username
更改了它。