I have a query which is doing something strange. This checkbox is in a while loop and it correctly lists out everything it needs to:
<input type='checkbox' name='rep[]' value='$invoiceID'>Reference Number: $invoiceID
<input type='hidden' name='billablehours[]' value='$billableTotal'>
When the form is submitted the values are inserted into the database using:
foreach ($_POST['rep'] as $index => $id) {
$sql2="INSERT into b_sale_basket (QUANTITY,LID,NAME)
VALUES
('".$_POST['billablehours'][$index]."','s1','".$_POST['rep'][$index]."')";
if (!mysqli_query($con,$sql2))
{
die('Error: ' . mysqli_error($con));
}
}
It inserts everything as it should do except billablehours. I have outputted the value of $billableTotal on each checkbox on the form page and the value is correct. For example it might equal 25 but when the button is pressed it inputs 37.5 which is another value of a checkbox.
Strange. Can anybody identify an issue?
reparray will only have one element0but thebillablehoursarray will have as many as are defined on the page.