Php 如何通过单击按钮添加更多行来更新表

Php 如何通过单击按钮添加更多行来更新表,php,button,html-table,Php,Button,Html Table,我正在尝试使用在文本框中输入的用户请求更新表。 因此,如果用户希望在订单中输入5行数据,他们会在文本框中键入“5”,点击“更新”按钮,然后用5行填充表格。 我相信我的代码中有逻辑,但由于某些原因它没有更新。你知道为什么吗 <table> <tr> <th class="textCol">Product Rows:</th> <td class="inputCol"><input type="text" name="

我正在尝试使用在文本框中输入的用户请求更新表。 因此,如果用户希望在订单中输入5行数据,他们会在文本框中键入“5”,点击“更新”按钮,然后用5行填充表格。 我相信我的代码中有逻辑,但由于某些原因它没有更新。你知道为什么吗

<table>
<tr>
    <th class="textCol">Product Rows:</th>
    <td class="inputCol"><input type="text" name="rows"></td>
    <td><input class="update" type="button" name="update" value="Update"></td>
    <td class="inputCol"></td>
</tr>
</table>

<table class="bottomTable">
    <tr>
        <th class="textCol">Product</th>
        <th class="textCol">Quantity</th>
        <th class="textCol">Unit Price</th>
        <th class="textCol">Total Price</th>
    </tr>
<?
    if (isset($_POST['update']))
    {
        //Execute this code if the update button is clicked.
        $num = $_POST['rows'];

        for ($i=0; $i<$num; $i++) { ?>
          echo "<tr>
                    <td class="inputCol2"><input type="text" name="product[$i]" ></td>
                    <td class="inputCol2"><input type="text" name="quantity[$i]" ></td>
                    <td class="inputCol2">$<input type="text" name="unit[$i]" ></td>
                    <td class="inputCol2">$<input type="text" name="total[$i]" ></td>
                </tr>";
    <? } ?>
<? } else {?>

    <tr>
        <td class="textCol"></td>
        <td class="textCol"></td>
        <td class="textCol">Total Order:</td>
        <td class="inputCol2">$<input type="text" name="total6"></td>
    </tr>
<? } ?>

</table>

产品行:
产品
量
单价
总价
回声“
$
$
";
总订单:
$

输入是否在表单中?如果它不在表单中,则默认情况下作为$\u GET而不是$\u POST提交,因此If()会始终发现它为FALSE。


<form method="post">
<table>
    <tr>
        <th class="textCol">Product Rows:</th>
        <td class="inputCol"><input type="text" name="rows"></td>
        <td><input class="update" type="submit" name="update" value="Update"></td>
        <td class="inputCol"></td>
    </tr>
    <tr>
        <th class="textCol">Product</th>
        <th class="textCol">Quantity</th>
        <th class="textCol">Unit Price</th>
        <th class="textCol">Total Price</th>
    </tr>
<?
    if (isset($_POST['update']))
    {
        //Execute this code if the update button is clicked.
        $num = $_POST['rows'];

        for ($i=0; $i<$num; $i++) { ?>
            <tr>
                <td class="inputCol2"><input type="text" name="'product' . <?=[$i]?>" ></td>
                <td class="inputCol2"><input type="text" name="'quantity' . <?=[$i]?>" ></td>
                <td class="inputCol2">$<input type="text" name="'unit' . <?=[$i]?>" ></td>
                <td class="inputCol2">$<input type="text" name="'total' . <?=[$i]?>" ></td>
            </tr>
    <? } ?>
<? } else {?>
    <tr>
        <td class="textCol"></td>
        <td class="textCol"></td>
        <td class="textCol">Total Order:</td>
        <td class="inputCol2">$<input type="text" name="total6"></td>
    </tr>
<? } ?>
</table>
</form>
产品行: 产品 量 单价 总价
要更新的代码在哪里?谢谢,我忘了它默认为$\u GET方法。我在表格周围添加了表单标签,还将更新按钮的输入更改为“提交”,因为它只是一个“按钮”,可以工作!