Am new to php… I have been battling on my dynamic checkboxes in such a way that if none is checked the form is return, also I need to retain what was checked when the form postback due to other invalid inputs.
$result = mysql_query("SELECT * FROM course") or die(mysql_error());
if ($result)
{
while ($row = mysql_fetch_array($result)){
if (isset($_POST['courses']) and $_POST['courses'] == $row['cid']) {echo $row['cid'];}
print "<input type=\"checkbox\" name=\"courses[]\" value=\"$row[cid]\">$row[cname]\n";
}
}
Help needed purely on php codes. Thanks in advance
Do this where the checkbox appears in the HTML on your php page:
This will retain the checkbox state after the form has been posted.
UPDATE:
For your code, just do it like this, I think:
EDIT: The condition needs to change too, I think, as I show in the code above.