here i am again with an amateur question about executing a query statement for multiple textboxes.
I made the following code, standard there are 4 textboxes but with javascript the user has a option to add more textboxes, which will be having continued naming following productg[4]
so productg[5]
etc. I need this to work with these 4 for now, thus the reason i have not posted the javascript part.
When executing this code, i do get a result as echo with all the textboxesvalues that were filled in, but in my database only 1 row is added, when i expect there to be 4.
If more information is needed to give me sufficient advise, i´ll provide it as best as i can.
HTML
<div id="productgroepen">
<div>
<label>Product groep 1</label>
<input type="text" name="productg[1]" />
</div>
<div>
<label>Product groep 2</label>
<input type="text" name="productg[2]" />
</div>
<div>
<label>Product groep 3</label>
<input type="text" name="productg[3]" />
</div>
<div>
<label>Product groep 4</label>
<input type="text" name="productg[4]" />
</div>
</div>
PHP
$total = 4;
for($i=1; $i<=$total; $i++)
{
if(isset($_POST['productg']) && isset($_POST['productg'][$i]))
{
$product = $_POST['productg'][$i];
$productquery = mysqli_query($conn, "INSERT INTO productgroepen SET id = 'LAST_INSERT_ID()' , levid ='$hidresult' , productgroep = '$product'");
if($productquery === false)
{
throw new Exception('Query failed: ' . mysqli_error($conn) );
}
}
}