This is my code when i ECHO out its show all POST array , but when mysqli_query action run it only insert the last value. How to insert all data in query? Can anyone help me please...
$ser = $_POST['serial'];
foreach ($ser as $seria) {
echo $serial = $seria;
}
$re = $_POST['ref_no'];
foreach ($re as $refe) {
echo $ref = $refe;
}
$des = $_POST['desc'];
foreach ($des as $desce) {
echo $desc = $desce;
}
$uni = $_POST['unitss'];
foreach ($uni as $units) {
echo $unit = $units;
}
$qt = $_POST['qty'];
foreach ($qt as $qtys) {
echo $qty = $qtys;
}
$pric = $_POST['price'];
foreach ($pric as $prices) {
echo $price = $prices;
}
$amoun = $_POST['amount'];
foreach ($amoun as $amounts) {
echo $amount = $amounts;
}
mysqli_query($con, "INSERT into purchase_order (po_id, po_no, serial_no, ref_no, description, unit, qty, price, amount, status) VALUES ('', '".$po_nom."', '".$mr_no."', '".$serial."', '".$ref."', '".$desc."', '".$unit."', '".$qty."', '".$price."', '".$amount."', 'Pending')");
try this
$ser = $_POST['serial'];
foreach($ser as $keys=>$vals){
mysqli_query($con, "INSERT into purchase_order (po_id, serial_no, ref_no, description, unit, qty, price, amount, status) VALUES ('', '".$vals."', '".$_POST['ref'][$keys]."', '".$_POST['desc'][$keys]."', '".$_POST['unitss'][$keys]."', '".$_POST['qty'][$keys]."', '".$_POST['price'][$keys]."', '".$_POST['amount'][$keys]."', 'Pending')");
}
or you can also do this
$ser = $_POST['serial'];
foreach($ser as $keys=>$vals){
$values_array[]="('', '".$vals."', '".$_POST['ref'][$keys]."', '".$_POST['desc'][$keys]."', '".$_POST['unitss'][$keys]."', '".$_POST['qty'][$keys]."', '".$_POST['price'][$keys]."', '".$_POST['amount'][$keys]."', 'Pending')";
}
$values=implode(",",$values_array);
mysqli_query($con, "INSERT into purchase_order (po_id, serial_no, ref_no, description, unit, qty, price, amount, status) VALUES ".$values." ");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments