0

我有一个html表格,有 13 个<input>字段和大约。92 个不同的行,创建使用它从数据库php中提取记录。mySQL出于某种原因,当我为这个字段分配了一个名称时,它会导致我的<input type="submit" name="update_submit">按钮无法设置。如果我更改名称,没关系,但如果我删除名称,它将允许其他字段更新就好了。

这是我的表单代码片段($i自动递增):

上顶...

<form method="post" action="process_form.php">
<table>
<tr>

再向下...

echo "<td align=\"center\" class=\"edit_emp_comp_exp_cell\"><input type=\"text\" maxlength=\"10\" size=\"10\" id=\"Lic_Comp_Exp$i\" name=\"Lic_Comp_Exp[]\" value=\"" . $emp_query['Lic_Comp_Exp'] . "\">";

<input type="submit" name="update_submit" style="width:100px;" value="UPDATE">

再向下...

</tr>
</table>
</form>

这是我的process_form:

if(isset($_POST['update_submit']))
{
$id = $_POST['Emp_ID'];
$name = $_POST['Emp_Name'];
$phone = $_POST['Emp_Phone'];
$start = $_POST['Start_Date'];
$leave = $_POST['Paid_Leave'];
$aca = $_POST['Emp_ACA'];
$licauth = $_POST['Lic_Auth_ID'];
$authexp = $_POST['Lic_Auth_Exp'];
$liccomp = $_POST['Lic_Comp_ID'];
$compexp = $_POST['Lic_Comp_Exp'];
$miscp  = $_POST['MiscP_ID'];
$position = $_POST['Pos_ID'];
$active = $_POST['activeBox'];
$i = 0;

foreach($id as $update) 
        {
        if (!isset($active[$i])) { $active[$i] = 0; }
        $sql = ("UPDATE employee SET Emp_Name = '$name[$i]', Emp_Phone = '$phone[$i]', Emp_Start_Date = '$start[$i]', Paid_Leave = '$leave[$i]', Emp_ACA = '$aca[$i]', Lic_Auth_ID = '$licauth[$i]', Lic_Auth_Exp = '$authexp[$i]', Lic_Comp_ID = '$liccomp[$i]', Lic_Comp_Exp = '$compexp[$i]', MiscP_ID = '$miscp[$i]', Pos_ID = '$position[$i]', Emp_Active = '$active[$i]' WHERE Emp_ID = '$update'");

        echo "SQL: " . $sql . "<br>";

        if(!$result_employee_update = $mysqli->query($sql))
            {
            $errors[] = "There was an error updating the employee table. MySqli Error Number: " . $mysqli->errno . "";
            goto end;
            }
        $i++;
        }
goto redirect;
}

我完全不知所措,整个上午都在进行故障排除,我非常感谢一些帮助。

更新:当我更改if(isset($_POST['update_submit']))if(!isset($_POST['update_submit']))运行它时,我收到一个错误:

"Notice: Undefined offset: 83 ... on line 31"

第 31 行是我的

`$sql = ("UPDATE employee SET Emp_Name = '$name[$i]', Emp_Phone = '$phone[$i]', Emp_Start_Date = '$start[$i]', Paid_Leave = '$leave[$i]', Emp_ACA = '$aca[$i]', Lic_Auth_ID = '$licauth[$i]', Lic_Auth_Exp = '$authexp[$i]', Lic_Comp_ID = '$liccomp[$i]', Lic_Comp_Exp = '$compexp[$i]', MiscP_ID = '$miscp[$i]', Pos_ID = '$position[$i]', Emp_Active = '$active[$i]' WHERE Emp_ID = '$update'");`

我认为这意味着我<input>的一个不是array,对吧?如果是这样,我不知道那是怎么回事,它就在table那里并且它是从database.

UPDATE2:我想我已经弄清楚了,但我不知道如何解决它。我尝试离开name="Lic_Auth_Exp"name="Lic_Comp_Exp"然后name从其他input字段中删除两个不同的属性。这样做之后,它似乎运行了代码。所以问题不在于这些特定字段,而似乎是因为$_POST传递了超过 11 个值。我查看了php.ini文件,看看是否有任何限制,但我什么也没看到。有谁知道这可能是什么原因造成的??

4

3 回答 3

1
  1. 在 php 中转储$_POST以检查它是否符合您的期望。

  2. 验证表单结构。所有输入都在同一个标​​签内吗?

于 2013-01-03T07:21:47.110 回答
0

延长条件

if(isset($_POST['update_submit']) && $_POST['update_submit']=="you-given-name-just-null")
于 2013-01-03T07:23:24.663 回答
0

我敢打赌,我已经花费了超过 14 个小时来解决这个问题,@angel 也很友好地进行了深入尝试。最后我想通了。

问题最终是在我的文件max_input_vars中设置得不够高。php.ini更大的问题是该设置在您添加之前实际上并不存在,因此当您查看文件时,您首先看不到任何设置限制的内容!

So, to recap. The issue wasn't because of the name="" attribute like I was lead to believe. I figured this out when I removed two other names from two different input fields, suddenly it worked fine and it was only when I had these extra fields that it wouldn't work. The next clue came thanks to @Jakub Sacha when he suggested to use the var_dump($_POST) function. When I started looking at the numbers, it finally clicked that the total amount of fields being passed added up to 1000. After a Google search for PHP 1000 Limit I found out about this max_input_vars setting.

Hopefully this will help someone else out and prevent hours of troubleshooting!

于 2013-01-05T11:42:34.717 回答