【发布时间】:2019-12-24 03:54:14
【问题描述】:
我有以下从数据库生成的动态表。
<form method="post">
<?php
while($result = mysqli_fetch_array($tableQueryExecute)){
$shift1Oa = $result['operator1'];
$shift2Oa = $result['operator2'];
$shift3Oa = $result['operator3'];
$shift4Oa = $result['operator4'];
$id = $result['srNumber'];
echo '<td scope="row">'.$id.'</td>
<td>
<input type="number" class="form-control" id="shift1PinCount" name="shift1PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 1" min=0>
</td>
<td>
<input type="text" class="form-control" id="shift1Oa" name="shift1Oa" value="'.$shift1Oa.'" disabled>
</td>
<td>
<input type="number" class="form-control" id="shift2PinCount" name="shift2PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 2" min=0>
</td>
<td>
<input type="text" class="form-control" id="shift2Oa" name="shift2Oa" value="'.$shift2Oa.'" disabled>
</td>
<td>
<input type="number" class="form-control" id="shift3PinCount" name="shift3PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 3" min=0>
</td>
<td>
<input type="text" class="form-control" id="shift3Oa" name="shift3Oa" value="'.$shift3Oa.'" disabled>
</td>
<td>
<input type="number" class="form-control" id="shift4PinCount" name="shift4PinCount" placeholder="Pin Count" title="Please key in Pin Count for Shift 4" min=0>
</td>
<td>
<input type="text" class="form-control" id="shift4Oa" name="shift4Oa" value="'.$shift4Oa.'" disabled>
</td>
<td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="'.date("Y-m-d").'"></td>
<td>
<a href="supervisorEdit.php?source='.$id.'" type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">Save</a>
</td>';
}
</form>
我需要什么
假设用户单击了该表特定行的Save 按钮,我希望使用php $_POST 或$_GET 方法将该行的相应值保存在数据库中,如下所示
if(isset($_GET['source'])){
$sourceId = $_GET['source'];
}
问题
我的问题是,我不知道如何获取表单的 $_POST 值,因为每个项目的名称都是动态生成的。我尝试通过按照以下方式向每个元素添加唯一的 $id 值来使每个元素的名称唯一。
<input type="text" class="form-control" id="shift1Oa" name="shift1Oa'.$id.'" value="'.$shift1Oa.'" disabled>
我无法通过以下方法捕获此唯一名称值。有谁知道为什么?
if(isset($_GET['source'])){
$sourceId = $_GET['source'];
echo $_GET['shift1Oa'.$sourceId];
}
编辑 1
为了获得更好的画面,下面是带有按钮的一行的截图
【问题讨论】:
标签: php html mysql post html-table