I have a list of checkboxes and save the checked values in an array. However, when someone clicks 'submit' and they get an error, all their checked boxes are forgotten. Usually I would let the script remember the checked boxes with a code like
IF checkbox value = OK { echo checked="checked"}
However, now I save it in an array and I have no idea how to do this?
<?php
$sql = "SELECT merknaam FROM merken";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
echo " <input type=\"checkbox\" name=\"merken[]\" value='" . $row['merknaam'] . "'> " . $row['merknaam'] . " <Br /> ";
}
?>
This is the code I use for the checkboxes. Next I display the array with this code:
$merkenstring = implode(",", $_POST['merken']);
echo $merkenstring;
Result: AC Ryan,Adidas,Agu,Cargo
I hope someone could give me a code example!