我遇到以下代码段的问题。我希望在使用“搜索”按钮提交表单时出现标题Search results
,并且我正在尝试使用称为搜索的隐藏输入来实现此功能。这个想法是,当表单被提交时,这个值被设置为'yes',这将显示标题,但这不是在这里发生的事情。任何人都可以告诉我我哪里出了错?使用表单提交将变量从HTML传递到PHP
<html>
<head>
<title>Search</title>
</head>
<body>
<h1>Search</h1>
<form name = "search" action = "<?=$PHP_SELF?>" method = "get">
Search for <input type = "text" name = "find" />
<input type = "hidden" name = "searching" value = "yes" />
<input type = "submit" name = "search" value = "Search" />
</form>
<?php
if ($searching == "yes")
{
echo "<h2>Search results</h2>";
}
?>
</body>
</html>
在旧版本的PHP中,所有来自GET和POST的变量都可用作全局变量(register_global = on),它即将显示您不能直接使用$搜索,但需要从$ _GET预定义变量中获取它。你显然不需要*来做到这一点 – 2011-03-13 00:16:43