Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.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_Post_Filtering_Unset - Fatal编程技术网

Php 如何取消设置从动态表单提交的某些值?

Php 如何取消设置从动态表单提交的某些值?,php,post,filtering,unset,Php,Post,Filtering,Unset,我有一个使用可变变量的动态表单,它工作得很好,但我遇到了一个问题,在表单提交过程中,一些POST值必须被删除 由于变量的性质和动态表单动态构建插入和更新查询的编程,我需要在将这些值处理为单个变量后从$\u POST中删除它们 部分表单处理部分位于foreach循环中,包含: $Fields = array(); $Values = array(); foreach ($_POST as $key=>$value ) : if (Contains("month", $key)) un

我有一个使用可变变量的动态表单,它工作得很好,但我遇到了一个问题,在表单提交过程中,一些POST值必须被删除

由于变量的性质和动态表单动态构建插入和更新查询的编程,我需要在将这些值处理为单个变量后从
$\u POST
中删除它们

部分表单处理部分位于foreach循环中,包含:

$Fields = array();
$Values = array();
foreach ($_POST as $key=>$value ) :
    if (Contains("month", $key)) unset($_POST);
    if (Contains("day", $key)) unset($_POST);
    if (Contains("year", $key)) unset($_POST);
    if (Contains("hour", $key)) unset($_POST);
    if (Contains("minute", $key)) unset($_POST);
    if (Contains("second", $key)) unset($_POST);
    $Fields[] = "`$key`";
    $Values[] = isNull($value, $DBName);
endforeach;

$sqlInsert = "INSERT INTO $TableName (".implode(",",$Fields).") VALUES (".implode(",",$Values).")";
Contains()
函数具有:

function Contains($searchWord, $fromString) {
    if (is_array($fromString)) :
        reset($fromString);
        $key = key($fromString);
        return strpos($key, $searchWord) !== FALSE;
    else:
        return strpos($fromString, $searchWord) !== FALSE;
    endif;
}
我尝试了我能想到的一切,包括:

foreach ($_POST as $key=>$value ) :
    if (Contains("month", $key)) unset($_POST[$key]);
    if (Contains("day", $key)) unset($_POST[$key]);
    if (Contains("year", $key)) unset($_POST[$key]);
    if (Contains("hour", $key)) unset($_POST[$key]);
    if (Contains("minute", $key)) unset($_POST[$key]);
    if (Contains("second", $key)) unset($_POST[$key]);
endforeach;

as
$key
应包含我试图
取消设置()
但未取消设置的POST字段的名称。有什么想法吗?

我刚改写并简化了我原来的问题,但这样做给了我一个似乎已经成功的想法。我没有使用unset,而是使用continue:

if (Contains("month", $key)) continue;
if (Contains("day", $key)) continue;
if (Contains("year", $key)) continue;
if (Contains("hour", $key)) continue;
if (Contains("minute", $key)) continue;
if (Contains("second", $key)) continue;

如果您在问题中提供更多细节,我可以为您提供一种更加精细/专业的方法。请提供一个您可能收到的真实的
$\u POST
数组和预期的生成查询(用变量的值替换变量)。你的查询不安全——我可以帮你解决这个问题;我要拿掉那个标签。