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>

    Well, it took me a few hours, but I figured it out. There was in fact no problem with the code itself. The issue related to the activity_ID field not incrementing. This was the issue, because this is a primary field and needs to be unique.

    Now I can finally get some sleep! 🙂

    Cheers,
    revez

    BTW - I also added a conditional that checks to ensure that all of the checkboxes are not empty before proceeding with foreach loop. This eliminated the Invalid argument error I received if the form was submitted and none of the checkboxes were selected:

    if(!empty($_POST['row']) ) { 
      foreach ($_POST['row'] as $value) { 
        $check = false; 
          foreach ($value as $field) { 
            if($field != '') { 
              $check = true; 
              break; 
            } 
          } 
    
      Write a Reply...