Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.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
如何检查下拉框是否与if语句匹配[PHP]_Php_Html - Fatal编程技术网

如何检查下拉框是否与if语句匹配[PHP]

如何检查下拉框是否与if语句匹配[PHP],php,html,Php,Html,我一直在编写一个脚本,我被困在一个小部分。我正在检查以确保用户提交的表单是安全的。但我不确定如何接近下拉框,这是我迄今为止的代码: if ($_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting. { $supportErrors[] = "Support type

我一直在编写一个脚本,我被困在一个小部分。我正在检查以确保用户提交的表单是安全的。但我不确定如何接近下拉框,这是我迄今为止的代码:

if ($_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting.
{
    $supportErrors[] = "Support type you've chosen was not found, possibly trying to exploit this script?";
}
我不确定这是否是检查其值的正确方法。这是脚本这一部分的HTML端:

<select name="type" id="type" size="1" style="border: 1px solid #000000; background-color: #FFFFFF;">
      <option value="1" selected>Support</option>
      <option value="2">Question</option>
      <option value="3">Complaint</option>
</select>

支持
问题:
抱怨

现在,据我所知,该值是通过“type”发布的数据——因此,在我看来,它不应该发布该值(1、2或3),然后在PHP端,检查它是否为1、2或3

您需要将条件逻辑从或更改为和:


如果($\u POST['type']!='1'和&$\u POST['type']!='2'和&$\u POST['type']!='3')…

您需要将条件逻辑从或更改为和:


如果($\u POST['type']!='1'和&$\u POST['type']!='2'和&$\u POST['type']!='3')…

您需要将条件逻辑从或更改为和:


如果($\u POST['type']!='1'和&$\u POST['type']!='2'和&$\u POST['type']!='3')…

您需要将条件逻辑从或更改为和:

if($\u POST['type']!='1'&&$\u POST['type']!='2'&&&$\u POST['type']!='3')…
in_array()在检查一个事物是否与多个选项之一匹配时是一个很好的解决方案

if (!in_array($_POST['type'],array(1,2,3))){..}
您应该在打开错误的情况下进行开发:

error_reporting(E_ALL);
ini_set('display_errors', 1);
在检查一件事是否与多个选项之一匹配时,in_array()是一个很好的解决方案

if (!in_array($_POST['type'],array(1,2,3))){..}
您应该在打开错误的情况下进行开发:

error_reporting(E_ALL);
ini_set('display_errors', 1);
在检查一件事是否与多个选项之一匹配时,in_array()是一个很好的解决方案

if (!in_array($_POST['type'],array(1,2,3))){..}
您应该在打开错误的情况下进行开发:

error_reporting(E_ALL);
ini_set('display_errors', 1);
在检查一件事是否与多个选项之一匹配时,in_array()是一个很好的解决方案

if (!in_array($_POST['type'],array(1,2,3))){..}
您应该在打开错误的情况下进行开发:

error_reporting(E_ALL);
ini_set('display_errors', 1);

确保使用ISSET检查表单是否已发布

<?php
if ( isset( $_POST['type'] ) and $_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting.
{
    $supportErrors[] = ("Support type you've chosen was not found, possibly trying to exploit this script?");
}
?>

确保使用ISSET检查表单是否已发布

<?php
if ( isset( $_POST['type'] ) and $_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting.
{
    $supportErrors[] = ("Support type you've chosen was not found, possibly trying to exploit this script?");
}
?>

确保使用ISSET检查表单是否已发布

<?php
if ( isset( $_POST['type'] ) and $_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting.
{
    $supportErrors[] = ("Support type you've chosen was not found, possibly trying to exploit this script?");
}
?>

确保使用ISSET检查表单是否已发布

<?php
if ( isset( $_POST['type'] ) and $_POST['type'] != '1' || $_POST['type'] != '2' || $_POST['type'] != '3') // Checks to see if the submitted type matches, prevents exploiting.
{
    $supportErrors[] = ("Support type you've chosen was not found, possibly trying to exploit this script?");
}
?>
//Assumimg type作为一个数值,我可以这样实现它
$type=0;
如果(isset($_POST['type']))$type=trim($_POST['type'])*1;
如果($type<1)
{
$supportErrors[]=“请指定类型”;
}
elseif($type>3)
{
$supportErrors[]=“无效类型”;
}
//将类型设为数值,我可能会这样实现
$type=0;
如果(isset($_POST['type']))$type=trim($_POST['type'])*1;
如果($type<1)
{
$supportErrors[]=“请指定类型”;
}
elseif($type>3)
{
$supportErrors[]=“无效类型”;
}
//将类型设为数值,我可能会这样实现
$type=0;
如果(isset($_POST['type']))$type=trim($_POST['type'])*1;
如果($type<1)
{
$supportErrors[]=“请指定类型”;
}
elseif($type>3)
{
$supportErrors[]=“无效类型”;
}
//将类型设为数值,我可能会这样实现
$type=0;
如果(isset($_POST['type']))$type=trim($_POST['type'])*1;
如果($type<1)
{
$supportErrors[]=“请指定类型”;
}
elseif($type>3)
{
$supportErrors[]=“无效类型”;
}

什么错误?请添加错误没有错误,它返回$supportErrors[]-因此它不能正常工作。“但是它抛出了错误。”。。。我明白了,我的回答是什么错误?请添加错误没有错误,它返回$supportErrors[]-因此它不能正常工作。“但是它抛出了错误。”。。。我明白了,我的回答是什么错误?请添加错误没有错误,它返回$supportErrors[]-因此它不能正常工作。“但是它抛出了错误。”。。。我明白了,我的回答是什么错误?请添加错误没有错误,它返回$supportErrors[]-因此它不能正常工作。“但是它抛出了错误。”。。。解释我明白了,我的答案如下(我的坏额外)需要,修复。但是空白页意味着你的开发过程中有错误检查,这是一个不好的想法(不好的额外)需要修复。但是空白页意味着你的开发过程中有错误检查,这是一个不好的想法(不好的额外)需要修复。但是空白页意味着你的开发过程中有错误检查,这是一个不好的想法(不好的额外)需要修复。但是空白页意味着你的开发过程中有错误检查,这是一个坏主意