对于我的迷你网络应用程序,我制作了一个注册表和登录表。它们看起来是一样的。两种形式的区别在于输入字段的名称。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Login</title>
<link rel="stylesheet" href="css/style.css">
<!--[if lt IE 9]><script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
</head>
<body>
<section class="container">
<div class="login">
<h1>Prijava za intervju</h1>
<form method="POST" action="logovanje.php">
<p><input type="text" name="user" placeholder="Korisnicko ime"></p>
<p><input type="text" name="pass" placeholder="Password"></p>
<p class="submit"><input type="submit" name="commit" value="Prijava"></p>
</form>
</div>
</body>
</html>
以下是PHP简单登录代码
<?php
require_once('databaseClass.php');
//---------------------------------------------------------------------
function logovanje()
{
*body of function*
}
//---------------------------------------------------------------------
print_r($_POST);//for testing
if (isset($_POST['user']) && isset($_POST['pass']))
{
if ($_POST['user'] !== '' && $_POST['pass'] !== '')
{
logovanje();
}
else
{
echo <<<END
*html page to echo if user and pass are empty*
END;
}
}
else
{
echo <<<END
*html page to echo if user and pass are not set*
END;
}
问题是每次提交表单时,$_POST
数组都是空的。这很奇怪。
如果我将$_POST['user']
更改为$_POST['*anyothername*']
,将$_POST['pass']
更改为$_POST['*anyothername*']
,则print_r($_POST)
显示"user"answers"pass"的值(这种行为对我来说是不合逻辑的)。
用户名'test6'和密码'test6':的示例
Array ( [user] => test6 [pass] => test6 [commit] => Prijava )
PHP代码是:
print_r($_POST);//for testing
if (isset($_POST['username111']) && isset($_POST['password222']))
{
如果我设置正确的代码(应该是这样):
print_r($_POST);//for testing
if (isset($_POST['user']) && isset($_POST['pass']))
{
则print_r($_POST)
返回空数组:
Array ( )
这让我很困惑。当PHP开始执行时,为什么$_POST
数组为空?
用于注册的具有相同结构的文件可以毫无问题地工作(唯一的区别是用于注册的文件具有函数register()而不是logovanje())。
解决了问题。其他一些文件的代码不正确:)Apache的配置被其他人搞砸了:)
Aitch,感谢您的帮助:D