If you have multiple form inputs with the same name, and that name ends in double square brackets []
, their values will be turned into an array when PHP populates $_POST
from the form.
So your jQuery button should insert a row with fields named like this:
<input type="text" name="item_name[]" value="" />
<input type="text" name="item_cost[]" value="" />
<input type="text" name="item_quantity[]" value="" />
In your PHP code that takes the form submission, you can process all the rows that exist like this:
//I used `item_name` as the loop termination condition,
//but any of the 3 keys would have worked
for ($i = 0; $i < count($_POST['item_name']); $i++) {
$item_name = $_POST['item_name'][$i];
$item_cost = $_POST['item_cost'][$i];
$item_quantity = $_POST['item_quantity'][$i];
//here, inside the loop, run your database query using the 3 values above
}