I am trying to use the HTML code at the bottom of this message to allow as user to select mulitple dates from a calendar by clicking on a checkbox (each checkbox represents one day of the month). Once complete, the user clicks on a submit button and the form data is sent (using PHP_SELF) to the same page that contains the PHP code below.
When testing this code, it will work, but it will only insert one record into the database, and that is all. This is quite puzzling as this is essentially the same code that I have used on a number of different scripts that have been working correctly for well over a year now. :bemused:
<?php
foreach ($_POST['row'] as $value) {
$check = false;
foreach ($value as $field) {
if($field != '') {
$check = true;
break;
}
}
if($check) {
// Insert the records into the database
mysql_query("INSERT INTO ACTIVITIES SET
activity_ID = '$activity_ID',
activity_type = '$activity_type',
activity_title = '$activity_title',
activity_description = '$activity_description',
activity_creator = '$member_name',
location = '$location',
activity_date = '$goal_year-$goal_month-".$value['goal_day']."',
activity_time = '$activity_time',
time_posted = '$current_time',
date_posted = '$current_date'");
$sql_results = mysql_affected_rows();
}
<tr>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_01.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_02.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_03.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_04.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_05.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_06.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
<td align="center" valign="middle"><input type="checkbox" name="<?php echo 'row['.$this_day_07.'][goal_day]'; ?>" value="<?php echo $this_day_01; ?>" <?php if(!empty($row[$this_day_01][goal_day])) { echo "checked"; } ?>></td>
</tr>