我有从数据库生成的以下动态表。
<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
or $_GET
方法如下
if(isset($_GET['source'])){
$sourceId = $_GET['source'];
}
Issue
我的问题是,我不知道如何获得$_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];
}
Edit 1
为了获得更好的图片,以下是带有按钮的一行的屏幕截图
如果我没记错的话,请纠正我..在这里您想从表单中获取所有值,对吧?单击按钮提交?
为什么你要制作这个按钮href?
假设我们有 3 个数据到我的 $result 中,循环如下所示
<form method="post" action="">
<tr>
<td scope="row"></td>
<input type ="text" name="sourece" value=1 />
<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="1" 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="2" 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="3" 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="4" disabled>
</td>
<td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
<td>
<input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
</td>
</form>
</tr>
<form method="post" action="">
<tr>
<td scope="row"></td>
<input type ="text" name="sourece" value=2 />
<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="11" 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="22" 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="33" 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="44" disabled>
</td>
<td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
<td>
<input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
</td>
</form>
</tr>
<form method="post" action="">
<tr>
<td scope="row"></td>
<input type ="text" name="sourece" value=3 />
<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="111" 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="222" 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="333" 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="444" disabled>
</td>
<td><input class="form-control" type="date" id="shiftDate" name="shiftDate" value="<?=date("Y-m-d")?>"></td>
<td>
<input type="submit" class="btn btn-primary" name="savePcData" id="savePcData" value="savePcData">
</td>
</form>
</tr>
<?php
if(isset($_POST['savePcData'])){
echo "<pre>";
print_r($_POST);
die('mms');
}
?>
Your Out put will be
here sourece是您的唯一 ID,可帮助您将数据更新到数据库中
从任何 tr(row) 提交表单后,您将使用 POST 方法重定向到同一页面,并获取该页面上该特定行的数据,以便您可以根据需要轻松更新它
您可以使用 print_r($_POST); 检查这一点在同一页上
如果您有任何疑问,请随时问我...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)