Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.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:没有收到一些POST变量?_Php_Html_Forms - Fatal编程技术网

PHP:没有收到一些POST变量?

PHP:没有收到一些POST变量?,php,html,forms,Php,Html,Forms,我有一个表单,它传递以下值: image_title, image_description, image_file 我想多次展示此表单,因此我做了以下工作: image_title_1, image_description_1, image_file_1 image_title_2, image_description_2, image_file_2 多次,所以我有字段1-10。我提交表单并打印出POST数组的内容,唯一的问题是“image_title_35;”之后的任何“image_ti

我有一个表单,它传递以下值:

image_title,
image_description,
image_file
我想多次展示此表单,因此我做了以下工作:

image_title_1,
image_description_1,
image_file_1

image_title_2,
image_description_2,
image_file_2
多次,所以我有字段1-10。我提交表单并打印出POST数组的内容,唯一的问题是“image_title_35;”之后的任何“image_title_35;”都不存在于数组中:但其他所有内容都存在

因此,该数组看起来像:

image_title_1 -> "title!"
image_description_1 -> "description!"
image_file_1 -> file

image_description_2 -> "description!"
image_file_2 -> file

image_description_3 -> "description!"
image_file_3 -> file
所以为了弄清楚它是什么,我交换了描述和标题,但是标题在1之后仍然不显示。我没有做任何处理,我只是在触摸它之前打印出$\u POST数组。这毫无意义,是什么原因造成的

澄清一下:问题是“image_title_35;”(示例:image_title_3)除了image_title_1之外没有通过,即使我重新安排了顺序。我在输出之前不做任何处理

编辑,html源代码仅为:

<form method="post" action="">
    <input type="text" name="image_title_1"></input>
    <input type="text" name="image_description_1"></input>
    <input type="text" name="image_file_1"></input>

    <input type="text" name="image_title_2"></input>
    <input type="text" name="image_description_2"></input>
    <input type="text" name="image_file_2"></input>

    <input type="text" name="image_title_3"></input>
    <input type="text" name="image_description_3"></input>
    <input type="text" name="image_file_3"></input>

    <input type="submit" name="submit" value="submit"></input>
</form>

更好的解决方案是将它们转换为数组,请尝试以下方法:

<form method="post" action="">
    <input type="text" name="image_title[]"></input>
    <input type="text" name="image_description[]"></input>
    <input type="text" name="image_file[]"></input>

    <input type="submit" name="submit" value="submit"></input>
</form>

在字段名后面加上
[]
将其转换为数组。另一个好处是它也缩短了代码

一旦拥有了数组,就可以使用
foreach

foreach($_POST['image_title'] as $key => $value)
{
  // process them any way you want
}

代码是有效的。我只是剪贴你的表格,然后做一个测试

  Array
(
[image_title_1] => 1
[image_description_1] => 2
[image_file_1] => 3
[image_title_2] => 4
[image_description_2] => 5
[image_file_2] => 6
[image_title_3] => 7
[image_description_3] => 8
[image_file_3] => 9
[submit] => submit
)

你能显示表单的HTML源代码吗?向我们显示为你的表单生成的HTML。如果可以,你应该显示你的代码。我已经发布了表单,正如我所说的,它只是一个基本表单。PHP端只是“print_r($_POST);”。您为#1到#3输入了什么吗?默认情况下不显示空字段。
  Array
(
[image_title_1] => 1
[image_description_1] => 2
[image_file_1] => 3
[image_title_2] => 4
[image_description_2] => 5
[image_file_2] => 6
[image_title_3] => 7
[image_description_3] => 8
[image_file_3] => 9
[submit] => submit
)