jeudi 16 février 2017

Checkbox status is not saving

I have this problem that the change in checkbox status isn't affecting on a data unless the first one is unchecked. Example is below:

Here, I'm trying to update the data of try. I unchecked the 2nd-3rd-4th checkboxes but when saving, the changes didn't happen. enter image description here

But if I uncheck the checkboxes of Administration and try to save it, the changes happened. After that, I can uncheck now the checkboxes in try and save it. enter image description here

WHY IS THAT? WHY I CAN ONLY UPDATE THE DATA IN try IF CHECKBOXES IN Administration ARE UNCHECKED? MAYBE I'M MISSING OR FORGETTING SOMETHING.

Here are some pieces of my code: (display codes)

//fetching from table
$stmnt = $conn->query(".....");

if ($stmnt->rowCount() > 0){
    while ($row = $stmnt->fetch(PDO::FETCH_ASSOC)){
        //display of data
        $str .= ".....
                 .....
                 <td>
                     <input type='checkbox' name='hol_not_" . $row['id'] . "' /> 
                     <input type='checkbox' name='hol_reg_" . $row['id'] . "' /> 
                     <input type='checkbox' name='hol_dob_" . $row['id'] . "' /> 
                     <input type='checkbox' name='hol_spe_" . $row['id'] . "' /> 
                     <input type='checkbox' name='hol_obs_" . $row['id'] . "' />
                 </td>
                 .....
                 .....";
     }
}else{
    $str .= "<tr><td colspan='7'>NO RECORDS FOUND!</td></tr>";
}

echo $str;

(saving update codes)

if (isset($_POST['save'])){
    $stmnt = $conn->query("......");

    if ($stmnt->rowCount() > 0){
        while ($row = $stmnt->fetch(PDO::FETCH_ASSOC)){
            if (isset($_POST[$row['id']])){
                //first checkbox
                if (isset($_POST['hol_not_' . $row['id']]) == 1){ 
                    $hol_not_ = 'Y'; 
                } else{ 
                    $hol_not_ = 'N'; 
                }

                //second checkbox
                if (isset($_POST['hol_reg_' . $row['id']]) == 1){ 
                    $hol_reg_ = 'Y'; 
                } else{ 
                    $hol_reg_ = 'N'; 
                }

                //third checkbox
                if (isset($_POST['hol_dob_' . $row['id']]) == 1){ 
                    $hol_dob_ = 'Y'; 
                } else{ 
                    $hol_dob_ = 'N'; 
                }

                //fourth checkbox
                if (isset($_POST['hol_spe_' . $row['id']]) == 1){ 
                     $hol_spe_ = 'Y'; 
                } else{ 
                     $hol_spe_ = 'N'; 
                }

                //fifth checkbox
                if (isset($_POST['hol_obs_' . $row['id']]) == 1){ 
                    $hol_obs_ = 'Y'; 
                } else{ 
                     $hol_obs_ = 'N'; 
                }

                $qupdate = $conn->query("UPDATE .....
                    .....
                    hol_not = '" . $hol_not_ . "', 
                    hol_reg = '" . $hol_reg_ . "', 
                    hol_dob = '" . $hol_dob_ . "', 
                    hol_spe = '" . $hol_spe_ . "', 
                    hol_obs = '" . $hol_obs_ . "', 
                    .....
                    .....
                    WHERE id = '" . $row['id'] . "'");
            }
         }
     }

            if ($qupdate->rowCount() > 0)
               echo "<div class='instruct'>Changes saved.</div>";
 }




Aucun commentaire:

Enregistrer un commentaire