I am currently trying to design an invoice generator. Essentially the page has input fields along side a table which allows you to create extra rows to input more data.
I need this data to be stored in database to be called in the future to be turned into a downloadable .pdf
My current issue is getting the data from the table into the database. So far my code only inputs the first row of data. Am i going the complete wrong way about this?
<tr id="item0" class="item">
<td>
1
</td>
<td>
<input name='item_name[0]' type='text' placeholder='Name' class='form-control input-md' />
</td>
<td>
<input name='quantity[0]' type='text' placeholder='0' class='form-control input-md' />
</td>
<td>
<input name='price[0]' type='text' placeholder='£0.00' class='form-control input-md' />
</td>
<td>
total
</td>
</tr>
<tr id="item1" class="item">
<td>
1
</td>
<td>
<input name='item_name[1]' type='text' placeholder='Name' class='form-control input-md' />
</td>
<td>
<input name='quantity[1]' type='text' placeholder='0' class='form-control input-md' />
</td>
<td>
<input name='price[1]' type='text' placeholder='£0.00' class='form-control input-md' />
</td>
<td>
total
</td>
</tr>
And the php...
if (isset($_POST['submit'])) {
print_r(array_values($_POST['item_name']));
}
$i = 0;
foreach($_POST as $val) {
$item_name = $_POST['item_name'][$i];
$quantity = $_POST['quantity'][$i];
$price = $_POST['price'][$i];
$sqlConnect - > query("INSERT INTO `Invoices` (`id`, `item_name`, `quantity`, `price`) VALUES ('".$i.
"', '".$item_name.
"', '".$quantity.
"', '".$price.
"')");
$i++;
}
}
else {
die('No item data to process');
}