I have these checkboxes used for identifying (if checked) should email the respective client, it's supposed to be pre-checked.
But when it is pre-checked, and then when I unchecked one checkbox e.g multipayment_email[1], when submitted to PHP the one getting unset is the last index multipayment_email[4].
list_payments.php
:
<form method="POST">
<?php while($row = mysqli_fetch_array($selectQuery) { ?>
<input type="text" name="multipayment_name[]" required/>
<input type="checkbox" name="multipayment_email[]" checked />
<?php } ?>
</form>
SUBMIT_payment.php:
$names = $_POST['multipayment_name'];
$emails = $_POST['multipayment_email'];
foreach ($names as $key => $name)
{
$email = isset($emails[$key]) ? 1:0;
$query = "INSERT INTO payments() VALUES (NULL, '$name', $email)";
$response['message'] .= $query."<br/>";
}
die(json_encode($response));
So when I submit the form this is the output (given that I unchecked the 2nd index out of 5 check boxes):
"INSERT INTO payments() VALUES (NULL, '1 waw', 1)"
"INSERT INTO payments() VALUES (NULL, '2 wew', 1)"
"INSERT INTO payments() VALUES (NULL, '3 wiw', 1)"
"INSERT INTO payments() VALUES (NULL, '4 wow', 1)"
"INSERT INTO payments() VALUES (NULL, '5 wuw', 0)"
It should be
"INSERT INTO payments() VALUES (NULL, '2 wew', 0)"
any enlightenment?