I have a dynamic form that has all dynamic arrays being set to my php mysql insert script. The records only get inserted correctly if I have all of my radio buttons checked. If I leave any unchecked random records get inserted. It's an attendance table and the inputs below repeat for each person. I'm checking their option with the radio button.
I've looked at the js hack of assigning a hidden input and disabling it if one of my radio buttons get checked but I find that a little weird.
My radio buttons have a value of 1 attend or 2 dive and I'm checking for that value in my script. I have a +1 set on the [$key+1] but that only works if all radios are checked. I appreciate any help pointing me in the correct direction as to setting my loop to only grab the data in the array when the radio is checked.
Thanks for looking
The two offending radio buttons are setup like this with the rest off the variables being set from hidden fields and are all filled with actual values. Everything gets insert if I don't use radio buttons in the form or if they're all checked.
<input type="radio" name="dive_attend_points['.$row1['_rowid_'].'][dive_attend]" value="'.$dive_points.'">
<input type="radio" name="dive_attend_points['.$row1['_rowid_'].'][dive_attend]" value="'.$attend_points.'">
<input type="hidden" name="_rowid_[]" value="' .$row1['_rowid_']. '">
<input type="hidden" name="location_date[]" value="' .$location_date. '">
<input type="hidden" name="location_name[]" value="' .$location_name. '">
<input type="hidden" name="first_name[]" value="' .$row1['first_name']. '">
<input type="hidden" name="last_name[]" value="' .$row1['last_name']. '">
<input type="hidden" name="cert_agency[]" value="' .$row1['cert_agency']. '">
<input type="hidden" name="high_cert[]" value="' .$row1['high_cert']. '">
<input type="hidden" name="email[]" value="' .$row1['email']. '">
<input type="hidden" name="phone_number[]" value="' .$row1['phone_number']. '">
<input type="hidden" name="photo_release[]" value="' .$row1['photo_release']. '">
<input type="hidden" name="diver_pic[]" value="' .$row1['diver_pic']. '">
<input type="hidden" name="submitted_email[]" value="' . $submitted_email . '">
<input type="hidden" name="food_option[]" value="' .$row2['food_option']. '">
My php loop is setup like this.
foreach ($_POST['location_date'] as $key => $value) {
$_rowid_ = $_POST['_rowid_'][$key];
$location_date = $_POST['location_date'][$key];
$location_name = $_POST['location_name'][$key];
$first_name = $_POST['first_name'][$key];
$last_name = $_POST['last_name'][$key];
$cert_agency = $_POST['cert_agency'][$key];
$high_cert = $_POST['high_cert'][$key];
$email = $_POST['email'][$key];
$phone_number= $_POST['phone_number'][$key];
$photo_release = $_POST['photo_release'][$key];
$diver_pic = $_POST['diver_pic'][$key];
$submitted_email = $_POST['submitted_email'][$key];
$food_option = $_POST['food_option'][$key];
foreach ($_POST['dive_attend_points'][$key+1] as $row) {
$dive_attend = $row['dive_attend'];
if (!empty($dive_attend)) {
if($dive_attend == 1) {
$dive_points = 0;
$attend_points = 1;
} elseif($dive_attend == 2) {
$dive_points = 2;
$attend_points = 0;
}
}
}
if($dive_attend == 1 || $dive_attend == 2){
//mysql insert here.
}
}