You can change your HTML to
<input name="product_name[]" .. />
And then you will be able to manipulate $_POST["product_name"]
as an array, containing all posted values.
You need to do the above for both the product_name
input, and the qty
input, so that you can do any necessary actions.
If you want to insert multiple records based on your quantity, your code must look something like:
<?php
for($i = 0; $i < count($_POST['product_name']); $i++) {
$product = $_POST['product_name'][$i];
for ($j = 0; $j < $_POST['qty'][$i]; $j++) {
// insert $product
}
}
?>
If your quantity is just another column in the product table, then your code should look like:
<?php
for($i = 0; $i < count($_POST['product_name']); $i++) {
$product = $_POST['product_name'][$i];
$query = 'INSERT INTO .. (`product_name`, `qty`) '.
' VALUES ("'.$product.'", "'.$_POST['qty'][$i].'")';
}
?>
Keep in mind that this is just an example. You need to check and escape values in real code.