Php 如何在MYSQL中每次点击按钮更新多行表单?

Php 如何在MYSQL中每次点击按钮更新多行表单?,php,html,mysql,Php,Html,Mysql,我正在开发一个php网站,为一家电气设计公司的地面激光扫描数据导出排序数据。当一行数据出现时,表单在MYSQL中会很好地更新,但当我显示两行或更多行数据时,当单击submit but时,多行数据会相互冲突 我的目标是分别对每行数据进行排序,并在单击行上的submit时通过MYSQL进行更新。但正如我所说,多行冲突。我可以告诉您如何对其重新编码,以指定仅在某一行上以表单形式输入的数据吗 问题还源于希望通过表单显示每个单元格中的当前现有数据,以便我知道输入了哪些数据,哪些数据没有输入 我为不整洁的编

我正在开发一个php网站,为一家电气设计公司的地面激光扫描数据导出排序数据。当一行数据出现时,表单在MYSQL中会很好地更新,但当我显示两行或更多行数据时,当单击submit but时,多行数据会相互冲突

我的目标是分别对每行数据进行排序,并在单击行上的submit时通过MYSQL进行更新。但正如我所说,多行冲突。我可以告诉您如何对其重新编码,以指定仅在某一行上以表单形式输入的数据吗

问题还源于希望通过表单显示每个单元格中的当前现有数据,以便我知道输入了哪些数据,哪些数据没有输入

我为不整洁的编码深表歉意,您可能会认为我对这一点非常陌生。这不是我的职业

while ($row = $result->fetch_object()) {    

    echo "<tr>";
    echo '<td>' . $row->point_number . '&nbsp;&nbsp;<a href="delete-final.php?id=' . $row->id . '">Delete</a></td>';
    echo "<td>" . $row->easting . "</td>";
    echo "<td>" . $row->northing . "</td>";
    echo "<td>" . $row->reduced_level . "</td>";
    echo "<td><input type='text' name='description' value='$row->description'  size='2'/></td>";
    echo "<td><input type='number' name='string_number' value='$row->string_number'  size='1'/></td>";
    echo "<td><input type='number' name='pole_number' value='$row->pole_number'  size='1'/></td>";
    // drop down menu for poles size
    echo    '<td><select name="pole_length">';
    echo    '<option>' . $row->pole_length . '</option>';
    echo    '<option value=' . $pole30 . '>30&apos;</option>';
    echo    '<option value=' . $pole35 . '>35&apos;</option>';
    echo    '<option value=' . $pole11 . '>11</option>';
    echo    '<option value=' . $pole12 . '>12</option>';
    echo    '<option value=' . $pole40 . '>40&apos;</option>';
    echo    '<option value=' . $pole125 . '>12.5</option>';
    echo    '<option value=' . $pole13 . '>13</option>';
    echo    '<option value=' . $pole45 . '>45&apos;</option>';
    echo    '<option value=' . $pole14 . '>14</option>';
    echo    '<option value=' . $pole15 . '>15</option>';
    echo    '<option value=' . $pole155 . '>15.5</option>';
    echo    '<option value=' . $pole17 . '>17</option>';
    echo    '<option value=' . $pole185 . '>18.5</option>';
    echo    '<option value=' . $pole20 . '>20</option>';
    echo    '</select></td>';
    // echo '<td>' . $row[8] . '</td>';
    // drop down menu for Pole strength
    echo    '<td><a>' . $row->pole_strength . '&nbsp;</a><select name="pole_strength">';
    echo    '<option></option>';
    echo    '<option value=' . $poleA . '>A</option>';
    echo    '<option value=' . $poleB . '>B</option>';
    echo    '<option value=' . $pole5 . '>5</option>';
    echo    '<option value=' . $pole8 . '>8</option>';
    echo    '<option value=' . $pole12 . '>12</option>';
    echo    '<option value=' . $pole16 . '>16</option>';
    echo    '<option value=' . $pole20 . '>20</option>';
    echo    '</select></td>';

    //echo '<td>' . $row[9] . '</td>';
    // drop down menu for Pole Type

    echo    '<td><a>' . $row->pole_type . '&nbsp;</a><select name="pole_type">';
    echo    '<option></option>';
    echo    '<option value=' . $poleWOOD . '>Wood</option>';
    echo    '<option value=' . $poleCONC . '>Concrete</option>';
    echo    '<option value=' . $poleSTEEL . '>Steel</option>';
    echo    '<option value=' . $poleSTOBIE . '>Stobie</option>';
    echo    '<option value=' . $poleIBCONC . '>I-be...Conc</option>';
    echo    '<option value=' . $poleFABST . '>Fab Steel</option>';
    echo    '</select></td>';

    echo '<td>' . $row->pole_top. '</td>';

    echo "<td><input type='text' name='remark' value='$row->remark'/></td>";

    echo "<td>" . $row->circuitheight_1 . "</td>";
    echo "<td>" . $row->circuitinsulatorleft_1 . "</td>";
    echo "<td>" . $row->circuitremark_1 . "</td>";
    echo "<td>" . $row->circuitheight_2 . "</td>";
    echo "<td>" . $row->circuitinsulatorleft_2 . "</td>";
    echo "<td>" . $row->circuitremark_2 . "</td>";
    echo "<td>" . $row->circuitheight_3 . "</td>";
    echo "<td>" . $row->circuitinsulatorleft_3 . "</td>";
    echo "<td>" . $row->circuitremark_3 . "</td>";
    echo "<td>" . $row->circuitheight_4 . "</td>";
    echo "<td>" . $row->circuitinsulatorleft_4 . "</td>";
    echo "<td>" . $row->circuitremark_4 . "</td>";
    echo "<td>" . $row->circuitheight_5 . "</td>";
    echo "<td>" . $row->circuitinsulatorleft_5 . "</td>";
    echo "<td>" . $row->circuitremark_5 . "</td>";
    echo "<td>" . $row->stayattachmentheight1 . "</td>";
    echo "<td><button type='submit' name='submit' value=' . $row->point_number . '/>SEND</td>";
    echo "</tr>";
}   

echo "</table>";


if (isset($_POST['submit']))

    {   


        $point_no = $_POST['submit'];
        $point_number = substr($point_no, 2, 3);
        $description = htmlentities($_POST['description'], ENT_QUOTES);
        $string_number = htmlentities($_POST['string_number'], ENT_QUOTES);
        $pole_number = htmlentities($_POST['pole_number'], ENT_QUOTES);
        $pole_length = htmlentities($_POST['pole_length'], ENT_QUOTES);
        $pole_strength = htmlentities($_POST['pole_strength'], ENT_QUOTES);
        $pole_type = htmlentities($_POST['pole_type'], ENT_QUOTES);
        $remark = htmlentities($_POST['remark'], ENT_QUOTES);



        if ($description == '' || $string_number == '')
            {

                $error = 'ERROR: Please fill in all required fields!';

                //echo "<h2>" . $row->$point_number  .  $easting  . $northing . $reduced_level ."</h2>";
            }
        else
            {

                if ($stmt = $mysqli->prepare("UPDATE final SET description = ?, string_number = ?, pole_number = ?, pole_length = ?, pole_strength = ?, pole_type = ?, remark = ? WHERE point_number=?"))
                    {
                        $stmt->bind_param("siissssi", $description, $string_number, $pole_number, $pole_length, $pole_strength, $pole_type, $remark, $point_number);
                        $stmt->execute();
                        $stmt->close();
                    }

                else
                    {
                        echo "ERROR: could not prepare SQL statement.";
                    }



            }

哦,上帝,那些回声。使用a你需要把每一行都变成一个单独的表单。是的,我只是赶时间,哈哈,总有一天我会整理一下。你可以将html元素名称指定为数组,即name=pole_length[],name=pole_type[]等等。现在浏览器发送所有信息,PHP将其解析为数组。因此,在PHP中,您可以使用for循环或foreach中的索引来访问它。只需打印\u r$\u POST即可查看结果。