2
我已經創建了表格,我們可以在其中添加多行一個接一個 我想插入提交按鈕上的所有行的數據。我能夠從我的多行只添加單列即頂行如何在SQLi中添加多行?
這是我的HTML代碼:
<div class = "table-responsive">
<table class="table table-responsive table-striped table-bordered table-condensed ">
<thead>
<tr>
<th class="text-center">#</th>
<th>Name Of DE</th>
<th>Game Plan Posted</th>
<th>Patch Name </th>
<th>Summary</th>
<th>P.O.B</th>
<th>Dr. Conversion </th>
<th>Remarks </th>
</tr>
</thead>
<tbody id="dataTable">
<tr>
<td><input type="checkbox" name="chk[]" /></td>
<td><input type = "text" name = "de[]"></td>
<td>
<select id="gamePlan" name="gamePlan[]">
<option>----- Select ------</option>
<option>Yes</option>
<option>No</option>
</select>
</td>
<td><input type = "text" name = "patch[]"></td>
<td>
<select id="summary" name="summary[]">
<option>----- Select ------</option>
<option>Yes</option>
<option>No</option>
</select>
</td>
<td><textarea type="textarea" name= "pob[]"></textarea></td>
<td><input type = "text" name = "drc[]"></td>
<td><input type = "text" name = "rem[]"></td>
</tr>
</tbody>
</table>
</div>
這裏是我的PHP代碼:
<?php
if(isset($_POST['submit'])){
foreach($_POST['de'] as $k => $name) {
$na =$db->escape($_POST['de'][$k]);
$pa =$db->escape($_POST['patch'][$k]);
$pob = $db->escape($_POST['pob'][$k]);
$dr = $db->escape($_POST['drc'][$k]);
$re = $db->escape($_POST['rem'][$k]);
$game = $db->escape($_POST['gamePlan'][$k]);
$sum = $db->escape($_POST['summary'][$k]);
// coqueryntinue insertion
$query = "INSERT INTO misrep(DE, game_plan, patch_name, summary, pob, dr_conversion, remark)
VALUES('$na', '$game', '$pa', '$sum','$pob','$dr', '$re')";
if($db->query($query)){
$session->msg('s',"Product added ");
redirect('tbl_report.php', false);
} else {
$session->msg('d',' Sorry failed to added!');
redirect('product.php', false);
}
}
}
幫助我解決它!由於
爲什麼你在第一次插入後做重定向? –
@YourCommonSense Thnx精湛的捕捉,只是刪除工作完美! thanx再次 –