enter image description here我想插入多個文本框只有兩個名稱。在所有這些texboxes我有名稱項目[]和數量[]。我試圖嵌套foreach循環,但增加了比預期更多的值。問題是$ _POST ['qty']。我可以選擇和添加項目[],但我不能添加數量整數值!如何插入兩個不同名稱的多個文本框?
<div class="col-md-12 diff">
<div class="col-md-4">
<p>Select Item</p>
<input style="color:black;" type="text" class="form-control items" name="items[]" placeholder="Search...">
<div class="side"></div>
</div>
<div class="col-md-2">
<p>QTY</p>
<input id="pats_input" class="form-control pats_tb" type="text" name="qty[]" placeholder="NO:">
<div class="side"></div>
</div>
</div>
<div class="col-md-12 diff">
<div class="col-md-4">
<p>Select Item</p>
<input style="color:black;" type="text" class="form-control items" name="items[]" placeholder="Search...">
<div class="side"></div>
</div>
<div class="col-md-2">
<p>QTY</p>
<input id="pats_input" class="form-control pats_tb" type="text" name="qty[]" placeholder="NO:">
<div class="side"></div>
</div>
</div>
function issueToEmployee(){
global $conn;
if(isset($_POST['pats']) && $_POST['pats'] !="" && isset($_POST['items']) && $_POST['items'] !="" && isset($_POST['qty'])){
$perstat = new getPerstat();
//get employee pats
$perstat->getPats($_POST['pats']);
$stock = new StockTable();
$qty = $_POST['qty'];
foreach($_POST['items'] as $item){
foreach($qty as $q){
if(!empty($item) && !empty($q)){
$stock->getItemByName($item);
$sql = $conn->prepare("INSERT INTO issues (empid, itemid) VALUES('$perstat->id','$stock->itemid')");
$sql->execute();
}
}
}
return true;
}else{
return false;
}
是,$項目= $ _ POST [「項目」],因爲輸入的名稱是項目[],一個添加上述值nd $ qty = $ _ POST ['qty'],輸入qty []。 – MaxPower
我編輯了代碼,希望它可以幫助 – cjatstackoverflow