使用$ _POST变量的PHP if语句似乎不起作用.为什么?

bri*_*ant 1 php variables post

在一台PHP服务器上,我有两个文件.一个文件(名称为"first.php")包含以下代码:

<html>
<head>
<title>First Page</title>
</head>
<body>
Please enter your password and age:
<form action="pass.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

另一个文件("pass.php")包含以下代码:

<html>
<head>
<title>Secon Page</title>
</head>
<body>
<?php
if ($fname=="Jack")
  echo "You are Jack!";
else
  echo "You are not Jack!";
?>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

据我了解,如果用户在第一页输入"Jack",则第二页应显示"You are Jack!" 线,但它不会发生.为什么会这样?

dar*_*saj 5

在第二页上,而不是检查$ fname,而是检查$ _POST ['fname'].我想这就是你所缺少的一切.