I try to update the data making use of checkboxes. But when one or more of the checkboxes is not checked, a notice is returned:
Notice: Undefined index: stats2 in E:\wamp\www\HOSPITAL\update.php on line 12
Notice: Undefined index: stats3 in E:\wamp\www\HOSPITAL\update.php on line 12
Notice: Undefined index: stats5 in E:\wamp\www\HOSPITAL\update.php on line 12
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("Hospital", $con);
mysql_query("UPDATE t2 SET HOSPNUM ='$_POST[hnum]', ROOMNUM='$_POST[rnum]', ADDATE= '$_POST[ad8]', ADTIME='$_POST[adtym]', LASTNAME='$_POST[lname]', FIRSTNAME='$_POST[fname]', MIDNAME='$_POST[mname]', CSTAT='$_POST[cs]', AGE='$_POST[age]', BDAY='$_POST[bday]', ADDRESS='$_POST[ad]', SEX='$_POST[sex]',
STAT='$_POST[stats1]', STAT2='$_POST[stats2]', STAT3='$_POST[stats3]', STAT4='$_POST[stats4]', STAT5='$_POST[stats5]', STAT6='$_POST[stats6]', STAT7='$_POST[stats8]', STAT8='$_POST[stats8]', NURSE='$_POST[nurse]'
WHERE TELNUM ='$_POST[telnum]'");
mysql_close($con)
?>
Could you help me, so that the notice would not show up?
This is the defined behavoir for checkboxes – only when set are they included in the form data.
You should use isset() to determine if the checkbox is ticked.
change it to
Another workaround which works is to add a hidden variable, with the same name, before the checkbox: e.g.