Store checkbox values in session display checked checkboxes

Hello,

I am trying to store values of checkboxes in SESSION.

I have a list of options which is generated from the database values:

PHP Code:

<?php
$result=mysql_query("SELECT * FROM table");
while ($row=mysql_fetch_assoc($result)) {
    $d_id=$row['id'];
    $d_name=$row['name'];
<input type="checkbox" name="checkbox[]" value="<?=$d_id?>><?=$d_name?></option>
<?php
}

?>

when I submit the form (which includes this option list) If there was a mistake I want to return checked checkboxes (the ones that were checked before form submission).
If everything goes well then I want to put checkbox values into the database… I guess using implode to comma separate them, but this is another story. I guess If I’ll know how to do this with the Session values I’ll be then able to get the values from database and pre check the checkboxes.

so can anyone help with the session thing? I need help with php code :\ i am a newbie…

When the form submit you will have access to the POST variable: checkbox. checkbox will be an array so you can do something like this:


if (isset($_POST['checkbox']) && is_array($_POST['checkbox'])) {
  foreach($_POST['checkbox'] as $value) {
    //echo $value -- will output the value from the input="checkbox"
  }
}