How to insert mulitple POST value from array using PHP

Jay Viluan

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')");
Bushra Shahid

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to post mulitple check box value using ajax jquery in laravel

From Dev

How to insert dynamic post array php?

From Dev

How to insert array of array in phpmyadmin using php

From Dev

How to split given array and get value from array using php

From Dev

PHP: How to insert array value into mysql statement

From Dev

PHP Insert array into multidimensional array by using an array value

From Dev

How to check the value is present inside an array and insert the value into database using PHP

From Dev

How to insert value to a 2 dimensions array from a 1 dimension array using Numpy

From Dev

How to get the value of a $_POST, if it is an array in PHP?

From Dev

How can get array key value from object using php

From Dev

Insert Mulitple Row Data from Jtable into database

From Dev

Using foreach for sql insert from dynamic post array

From Dev

How to post value using CURL php function?

From Dev

how to post the value in url using PHP

From Dev

How to Insert to database from loop Using PHP?

From Dev

How insert array value in each index of another array in php?

From Dev

How to post an array using AJAX to PHP?

From Dev

How to send array to PHP using jQuery $.post()

From Dev

How to receive array data from post in php?

From Dev

How to group the array by using array value, PHP

From Dev

How to group the array by using array value, PHP

From Dev

Assign Array Value to Variable and Insert into mysql using PHP

From Dev

PHP how to populate array from array by value

From Dev

Insert Check Box from Array Value on Change in PHP

From Dev

How to output a PHP array from ajax $_POST and split or explode the values into key and value

From Dev

Insert a "Select Value" option in dropdown list from array using jQuery

From Dev

PHP Cannot Insert Value Into Array

From Dev

Insert data from multiple array form inputs using php and mysql

From Dev

How to insert array value into single column and single row in php

Related Related

  1. 1

    How to post mulitple check box value using ajax jquery in laravel

  2. 2

    How to insert dynamic post array php?

  3. 3

    How to insert array of array in phpmyadmin using php

  4. 4

    How to split given array and get value from array using php

  5. 5

    PHP: How to insert array value into mysql statement

  6. 6

    PHP Insert array into multidimensional array by using an array value

  7. 7

    How to check the value is present inside an array and insert the value into database using PHP

  8. 8

    How to insert value to a 2 dimensions array from a 1 dimension array using Numpy

  9. 9

    How to get the value of a $_POST, if it is an array in PHP?

  10. 10

    How can get array key value from object using php

  11. 11

    Insert Mulitple Row Data from Jtable into database

  12. 12

    Using foreach for sql insert from dynamic post array

  13. 13

    How to post value using CURL php function?

  14. 14

    how to post the value in url using PHP

  15. 15

    How to Insert to database from loop Using PHP?

  16. 16

    How insert array value in each index of another array in php?

  17. 17

    How to post an array using AJAX to PHP?

  18. 18

    How to send array to PHP using jQuery $.post()

  19. 19

    How to receive array data from post in php?

  20. 20

    How to group the array by using array value, PHP

  21. 21

    How to group the array by using array value, PHP

  22. 22

    Assign Array Value to Variable and Insert into mysql using PHP

  23. 23

    PHP how to populate array from array by value

  24. 24

    Insert Check Box from Array Value on Change in PHP

  25. 25

    How to output a PHP array from ajax $_POST and split or explode the values into key and value

  26. 26

    Insert a "Select Value" option in dropdown list from array using jQuery

  27. 27

    PHP Cannot Insert Value Into Array

  28. 28

    Insert data from multiple array form inputs using php and mysql

  29. 29

    How to insert array value into single column and single row in php

HotTag

Archive