从html表创建具有PHP值

时间:2017-05-08 17:36:49

标签: php html mysql forms

我有一个充满小html表的页面,每个表都代表数据库表中的数据。这是一个单页打印报告,因此这些html表中有很多字段,但只有大约4或5个可能需要更改。

当用户选择记录并显示报告时,所有表格看起来都很棒,但我正在尝试找到一种方法来编辑和保存可能需要编辑的4或5。我知道我可以使用输入创建一个表单并将某些表行转换为输入,然后使用提交按钮我可以附加一个SQL语句来根据数据库表中的主键更新这些字段。

如何让这些表行成为表单中的可编辑输入?我已将整个页面包装在一个表单中,我甚至尝试将一个表包装在一个表单中作为测试,但我认为问题是我的表行语法。

这是我到目前为止所尝试的内容:

<form>
<table style="width:100%; border:none;
border-collapse:collapse;">

    <tr style="border:none;">
        <th style="border:none; text-align: left;" >Meter Test</th>
        <th style="border:none;">Test 1</th>
        <th style="border:none;">Test 2</th>
        <th style="border:none;">Test 3</th>
        <th style="border:none;">Test 4</th>
        <th style="border:none;">Test 5</th>
        <th style="border:none;">Test 6</th>
        <th style="border:none;">Test 7</th>
        <th style="border:none;">Test 8</th>
    </tr>
    <tr style="border: none;" >
        <td style="border:none; text-align: left;">Test Rate GPM: </td>
        <td><? echo $row['test1TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test2TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test3TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test4TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test5TestRateGPM'];?>&nbsp;</td>
        <td><? echo $row['test6TestRateGPM'];?>&nbsp;</td>
        <td><input type="text" value = "<?php $row['test7TestRateGPM'];?>">
        <td><input type="text" value = "<?php $row['test8TestRateGPM'];?>">        </td>

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

你可以看到我有正常的html表语法但是对于我正在测试的字段,我通过创建一行php并按照这种方式进行尝试,但网页上仍然没有表单。

1 个答案:

答案 0 :(得分:2)

我认为你只需要一个简单的输入文本字段。 这样做:

<td><input type="text" value = "<?php echo $row['test1TestRateGPM'];?>"></td>

并制作其中的多个。