1

I'm using this cycle to print all form $_POST data:

foreach($_POST as $name => $value) {
print "$name : $value<br>";
}

And at the end of result is submit button value (submit : Edit) and this cause error for me, because with this foreac cycle I'm adding data to excel document $name is cell, $value is cell value so how to remove button value from the list?

4

5 回答 5

7

您可以在执行 foreach 之前取消设置:

unset($_POST['submit']);
于 2012-05-28T12:13:22.647 回答
6

您的提交按钮不需要name在 HTML 中具有属性。如果它没有名称,则不会出现在 POST 数据中。

于 2012-05-28T12:13:23.017 回答
5

跳过它continue;

foreach($_POST as $name => $value) {
    if($name == "submit") continue;
    print "$name : $value<br>";
}
于 2012-05-28T12:13:25.590 回答
2

关于什么

foreach($_POST as $name => $value) {
    if($name != "submit"){
        print "$name : $value<br>";
    }
}
于 2012-05-28T12:13:29.307 回答
2

你在做什么不是好的做法。在这种情况下,将数据传递到 Excel 电子表格中,您不太可能遇到问题,但是,这是一个危险的习惯。

您已经设计了表单并为每个输入指定了名称,因此您可以提前知道 $_POST 数组将包含哪些索引。您应该仅显式引用 $_POST 数组中的那些值,并根据需要验证每个值。

不要忘记 $_POST 来自用户,因此是不可信的。额外的字段可以添加到 $_POST 数组中,就目前而言,您的代码将愉快地处理它们。

这可能是代码中的问题,也可能不是问题,但您至少应该考虑一下。

于 2012-05-28T14:59:00.367 回答