php - PHP FILTER_INPUT 不接收文本输入
问题描述
我在 macOSX 上的 MAMP 上运行 Apache 服务器。我遇到的问题是每个变量都在接收 filter_input() 但最后一个变量是“param”。我试过使用 $_POST['param']; 无济于事。我重新启动了 Apache 服务器,但没有任何改变。我确定这是一个语法错误,但这里的所有其他问题都是不相关且无益的。一个“没有接收输入的 PHP 表单”根本没有帮助。任何帮助表示赞赏:)
编辑:我已经意识到不需要使用 filter_input(INPUT_POST, "param") 因为我没有提供过滤器,并且 $_POST["param"] 是一种更容易接受的方法。
我的 HTML:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Code Writer (JAVA)</title>
</head>
<body>
<center>
<h1>Code Writer (JAVA)</h1>
</center>
<form action="backwards.php" method="post">
<fieldset>
<label>Enter visibility level (public/private/etc)</label>
<input type="text" name="first"><br>
<label>Static Method? Y/N</label>
<input type="text" name="static"><br>
<label>Enter return type (int/double/etc)</label>
<input type="text" name="return"><br>
<label>Enter method name?</label>
<input type="text" name="method"><br>
<label>Paramaters, if any</label>
<input type="text" name="param"><br>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
我的PHP:
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>backwards.php</title>
</head>
<body>
<?php
#Gather inputs
$first = filter_input(INPUT_POST, "first");
$static = filter_input(INPUT_POST, "static");
$return = filter_input(INPUT_POST, "return");
$method = filter_input(INPUT_POST, "method");
$param = filter_input(INPUT_POST, "param");
#Add to $output
$output = $first . " ";
if ($static == "Y") {
$output .= "static" . " ";
}
$output .= $return . " ";
$output .= $method . "(";
$output .= $param;
$output .= ") {} \n";
#Print $output
print($output);
?>
</body>
</html>
解决方案
事实证明,在使用@John Conde 的评论“var_dumb($_POST)”运行网站后,它就开始工作了。删除 var_dump 并且它仍然有效,尽管我对为什么感到困惑。问题已解决,但我仍然对为什么它现在有效,而不是以前有效。
推荐阅读
- java - 使用 sql 查询时,休眠删除级联不起作用
- android - addValueEventListener 没有在使用 Firebase 的 Android Studio 中启动
- ios - 如何在测试运行之间清理内存中的核心数据实例?
- http - 上传媒体文件时出现 Http 错误
- html - 无法在状态下正确添加和更新对象
- javascript - 在反应中更改组件内的元素
- r - 从另一个数据框中按多列过滤数据框
- python - Discord.py 我不能在 python 中使用 dict 来保存用户数据
- c# - 尝试在控制器中执行 ActionResult 方法时,ASP.NET“找不到资源”
- mysql - 在 SQL 中查找 IMDb 评分高于平均水平的电影的 IMDb 评分