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> </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.