I have done alot of reading about checkbox arrays, but I'm still trying to figure this out. I have a table (events_activityReg) with two fields activityReg_id and approval. I would like to display a list with activityReg_id as text and approval as a checkbox. Then, I would like to be able to check off some of the checkboxes and press the update button and have all the records updated. I know how to set all this up by using a detail page, but that is a cumbersome way of doing this. I know i have to create a checkbox array, but just can't get this to work. Could someone help me figure this out?
To create the form with the checkboxes, I have:

    <form name="form1" method="POST" action="<?php echo $editFormAction; ?>">
      <table border="0">
        <tr>
          <td><strong>approval</strong></td>
          <td><strong>activityReg_id</strong></td>
          <td>&nbsp;</td>
        </tr>
        <?php do { ?>
        <tr>
          <td><input <?php if (!(strcmp($row_Recordset1['approval'],1))) {echo "checked";} ?> name="approval" type="checkbox" id="approval" value="<?php echo $row_Recordset1['approval']; ?>"></td>
          <td><?php echo $row_Recordset1['activityReg_id']; ?></td>
          <td><a href="a_approval.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."activityReg_id=".$row_Recordset1['activityReg_id'] ?>">edit</a></td>
        </tr>
        <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
      </table>
      <p>
        <input type="submit" name="Submit" value="Submit">
        <input name="activityReg_id" type="hidden" id="activityReg_id" value="<?php echo $row_Recordset1['activityReg_id']; ?>">
</p>
      <input type="hidden" name="MM_update" value="form1">
    </form>  

To update the record I have:

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE events_activityReg SET approval=%s WHERE activityReg_id=%s",
                       GetSQLValueString(isset($_POST['approval']) ? "true" : "", "defined","1","0"),
                       GetSQLValueString($_POST['activityReg_id'], "int"));

  mysql_select_db($database_connProjectGRAD, $connProjectGRAD);
  $Result1 = mysql_query($updateSQL, $connProjectGRAD) or die(mysql_error());

  $updateGoTo = "a_approved.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}

I would really appreciate any help. Thanks.

    somthing like below willl query database and display check boxes
    named from approval with values activityReg_id

      <?php
    	$query = "SELECT * FROM events_activityReg ORDER BY activityReg_id";
    	$sql=mysql_query($query);
    	while($row = mysql_fetch_array($sql))
    	{
      echo"<input name=\"$row['approval']\" type=\"checkbox\" value=\"$row['activityReg_id']\">";
        }
    	?>    

      Thanks for the reply, but I think I was already creating the checkboxes. If I use your way, I still don't understand how to update all records that have a checkmark beside them. How would I do that?
      --rayne

        name your checkboxes activities[] and use $row['activityReg_id'] as values for them

        in the php script processing the form do

        echo '<pre>';
        print_r($_POST['activities']);
        echo '</pre>';

        and i'm sure you'll get it

          well I was looking at your code after having almost typed up something It hought would work, then I realized you are doing nothing inside the form to associate the array values with an ID in your database....

          w/o that your script will not function so well I dont think....

          unless I'm missing something.... If not... and I am right, then I can probably help you out with that too

            Thanks for the replies, everyone. Tekky: Do you mean to change it like this?

               
            <form name="form1" method="POST" action="<?php echo $editFormAction; ?>"> <table border="0"> <tr> <td><strong>approval</strong></td> <td><strong>activityReg_id</strong></td> <td>&nbsp;</td> </tr> <?php do { ?> <tr> <td><input <?php if (!(strcmp($row_Recordset1['approval'],1))) {echo "checked";} ?> name="approval[]" type="checkbox" id="approval[]" value="<?php echo $row_Recordset1['activityReg_idl']; ?>"></td> <td><?php echo $row_Recordset1['activityReg_id']; ?></td> <td><a href="a_approval.php?<?php echo $MM_keepURL.(($MM_keepURL!="")?"&":"")."activityReg_id=".$row_Recordset1['activityReg_id'] ?>">edit</a></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <p> <input type="submit" name="Submit" value="Submit"> <input name="activityReg_id" type="hidden" id="activityReg_id" value="<?php echo $row_Recordset1['activityReg_id']; ?>"> </p> <input type="hidden" name="MM_update" value="form1"> </form>

            Well, it dosn't work, but how do you mean I should change it.

              I would try inserting the ID as the value to the array you insert..... instead of a 1 or 0... (atleast thats what it looks like you are setting the VALUE= fields to....) the ID for the recordset would work best

                I know I am being really dense, but I need to insert a 1 or 0 in the approval column so I know if that activityReg_id is approved or not. Maybe I'm going about this all wrong. I need a list with activityReg_id (field which is unique) and approval (field which is a checkbox)

                So, it would be

                activityReg_id approval

                1 checkbox
                2 checkbox
                3 checkbox
                Submit

                Then, I could check the boxes I want to approve, click submit and a "1" would be written in the approval field corresponding with the activitityReg_id of all the records with a checkmark. If I went back and unchecked a box and then clicked submit, then a "0" would be written in the approval field corresponding with the activitityReg_id.
                Is this possible?
                --rayne

                  yup, so what you want to do (have your approved column DEFAULT to 0

                  you will never unapprove an approved event right?

                  then for your checkboxes

                  name=checkbox[' . $eventid . '] and value=1

                  then you can just do

                  $list = implode(',', $checkboxarrrayvariable);

                  UPDATE blah SET approved=1 WHERE eventid IN ($list)

                    Write a Reply...