Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查表单元素是否存在_Php - Fatal编程技术网

Php 检查表单元素是否存在

Php 检查表单元素是否存在,php,Php,我将表单元素保存到一个文件中,下面的操作按预期进行 $t_str .= "viewMandatory=".$_GET['viewMandatory'] ."\n"; 但我需要的是,如果只设置了$\u GET,那么它应该附加到“t\u str”字符串中 如果表单中未收到viewMandatory的值,则不应打印任何内容。如何将此支票添加到上述声明中 if (!empty($_GET['viewMandatory'])){ $t_str .= "viewMandatory=".$_GET['vie

我将表单元素保存到一个文件中,下面的操作按预期进行

$t_str .= "viewMandatory=".$_GET['viewMandatory'] ."\n";
但我需要的是,如果只设置了$\u GET,那么它应该附加到“t\u str”字符串中

如果表单中未收到viewMandatory的值,则不应打印任何内容。如何将此支票添加到上述声明中

if (!empty($_GET['viewMandatory'])){
$t_str .= "viewMandatory=".$_GET['viewMandatory'] ."\n";
}
在回答了292个问题之后,您应该已经遇到了empty()函数

这样,您的代码就更少了,这使得它更容易阅读(至少对我来说,我喜欢短表单),但是每次请求页面时,代码都会被执行。龙的解决方案并非如此

但是考虑一下代码注入。过滤器$\u在将其添加到字符串之前以正确的方式获取['viewMandatory']!否则很容易注入错误代码,例如:

www.yourpage.com/page.php?viewMandatory=';BAD_CODE_HERE (or " instead of ')

我想你缺少一个封闭的
()
,因为有很多问题,还有一个。
www.yourpage.com/page.php?viewMandatory=';BAD_CODE_HERE (or " instead of ')
Use php isset    


if (isset($_GET['viewMandatory'])){
$t_str .= "viewMandatory=".$_GET['viewMandatory'] ."\n";
}