This is embarrassing, but I have a form pulling data from mysql using php. Lots of different checkboxes in it. When user checks one or more boxes, all goes well; values are added and db is updated. And some php script makes sure those same checkboxes are then checked when page is reloaded. Here's the problem:
if I now uncheck one or more of those (automatically when the page loads) checked checkboxes and then do a submit, the form still treats those unchecked checkboxes as if they were checked. I have spent 6 solid hours going over and over my code, googling for answers and am now officially stuck. I'm sure this is some amateur newbie error. Can someone put me out of my misery? Code is below.
To update the data
if I now uncheck one or more of those (automatically when the page loads) checked checkboxes and then do a submit, the form still treats those unchecked checkboxes as if they were checked. I have spent 6 solid hours going over and over my code, googling for answers and am now officially stuck. I'm sure this is some amateur newbie error. Can someone put me out of my misery? Code is below.
To update the data
Code:
foreach($_POST as $key=>$value)
{
if(isset($key) && $key!="updatehr" && $key!="hwdates" && $key!="hrid" && $key!="hrclass")
{
if(substr_count($key,"hrreg"))
{
$keys=explode('hrreg',$key);
$studid=$keys[0];
$hrregdate=$keys[2];
$hrregitem=$keys[1];
$q="insert into hrregular values ('','$hrid','$studid','$hrregdate','$hrregitem')";
$r=mysql_query($q) or die(mysql_error());
}
}
}
Code:
for($j=1;$j<=20;++$j)
{
echo "<td>";
$q6="select hrregid from hrregular where studid='".$sid."' and hrregdate='".$dates[floor(($j-1)/4)]."' and hrregitem='".$arr1[($j-1)]."'";
$r6=mysql_query($q6) or die(mysql_error());
echo "<input style='margin-top:0px;' type=checkbox name='".$sid."hrreg".$arr1[($j-1)]."hrreg".$dates[floor(($j-1)/4)]."' ";
if(mysql_numrows($r6)==1)
{
echo " checked ";
}
echo "></td>";
}
Comment