I have code below to update checkbox value, either 1 or 0. The value can be passed if the checkbox is checked, but when the checkbox is unchecked/empty i got the following error Notice: Undefined variable: leave_mar
Is there anything I need to add in the code so that the value will be 0 if the checkbox is unchecked?
$checkannual = ($row['leave_al'] == '1') ? 'checked' : '';
$checkmarriage = ($row['leave_mar'] == '1') ? 'checked' : '';
<input type="checkbox" name="leave_al" value="1" '.$checkannual.'/> Annual Leave
<input type="checkbox" name="leave_mar" value="1" '.$checkmarriage.'/> Marriage Leave
Process
if(isset($_POST['submit']))
{
echo $leave_al = $_POST['leave_al'];
echo $leave_mar = $_POST['leave_mar'];
}
Thank you.
Aucun commentaire:
Enregistrer un commentaire