When I sending the data to the server in PHP with different input and same name I am not able to insert in my database through foreach function.
I tried my best and all others functions available on stackoverflow but they all are not helpful for me.
Please help me how to make this fix and what will the real code to achieve my code functions. as developer console sending data is -
productID: 21202,33201,44202,44202,33204
Qty: 1,2,3,4,5
PHP
foreach($_POST['productID'] as $product) {
foreach($_POST['Qty'] as $qty) {
$stmt = $con->prepare("INSERT INTO `table` (product,qty) VALUES (:p,:q)");
$stmt->execute(array(
':p' => $product,
':q' => $qty
));
}
}
echo $_POST['productID'];
response is = 21202,33204,332061
var_dump($_POST)and add the output to your question. We need to see the complete $_POST array to know what it contains.foreach(explode(',', $_POST['productID']) as $product) { foreach(explode(',', $_POST['Qty']) as $qty) {prepare()before the loop, then callexecute()with the new values inside the loop.Qty, but since you haven't added what I asked for, I'm just guessing.var_dump($_POST), notvar_dump($_POST['productID']). I've written the exact code snippet three times now. Just copy/paste what I wrote instead of trying to make your own version.