I have been trying to figure out how to insert a form multiple times into a database.
I have set up a form/calendar that will show a form, and a calendar with checkboxes in it. one of the inputs in the form is a day input. i was trying to get the form to insert the content from the form, once for everyday checked, and with the checked day being the submited date.

so for example, if u check the days the 5th, 9th , and 10th, it would insert the event 3 times, with the day of the event being 5, 9, and 10.

here is my code. i dont know what i am doing wrong.

PHP Code:
<?

require_once("config2.php");



session_start();



$db_connection mysql_connect ($DBHost$DBUser$DBPass) OR die (mysql_error());  

$db_select mysql_select_db ($DBName) or die (mysql_error());

$cookie_read explode("|"base64_decode($user));
          
//define variables to hold cookie values.
          
$username $cookie_read[1];


IF(isset(
$_POST['submit']))

{

    
$db_table $TBL_PR "events";

    

    
$_POST['description'] = substr($_POST['description'],0,500);

    
$_POST['title'] = substr($_POST['title'],0,30);
    
    

foreach (
$_POST['username'] as $row=>$name)
{
$username mysql_real_escape_string($name);
$day mysql_real_escape_string($_POST['day'][$row]);
$month mysql_real_escape_string($_POST['month'][$row]);
$year mysql_real_escape_string($_POST['year'][$row]);
$hour mysql_real_escape_string($_POST['hour'][$row]);
$minute mysql_real_escape_string($_POST['minute'][$row]);
$title mysql_real_escape_string($_POST['title'][$row]);
$description mysql_real_escape_string($_POST['description'][$row]);

mysql_query("INSERT INTO $db_table ( `username`, `event_id` , `event_day` , `event_month` , `event_year` , `event_time` , `event_title` , `event_desc` ) VALUES ('".addslashes($username)."', '', '".addslashes($day)."', '".addslashes($month)."', '".addslashes($year)."', '".addslashes($hour .":".$minute)."', '".addslashes($title)."', '".addslashes($description)."')") or die(mysql_error());


    
$_POST['month'] = $_POST['month'] + 1;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Add Workout</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language='javascript' type="text/javascript">

<!--

 function redirect_to(where, closewin)

 {

     opener.location= 'index.php?' + where;

     

     if (closewin == 1)

     {

         self.close();

     }

 }

  //-->

 </script>

</head>

<body onLoad="javascript:redirect_to('month=<? echo $_POST['month'].'&year='.$_POST['year']; ?>',1);">

</body>

</html>

<?

}

ELSE 


{

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>Add Workout</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="images/cal.css" rel="stylesheet" type="text/css">

</head>

<body>

<form name="form1" method="post" action="">

  <table width="480" border="0" cellspacing="0" cellpadding="0">

    <tr> 

      <td width="200" height="40" valign="top"><span class="addevent">Event Date</span><br> 

        <span class="addeventextrainfo">(MM/DD/YY)</span></td>

      <td height="40" valign="top"> <select name="month" id="month">

          <option value="1" <? IF($_GET['month'] == "1"){ echo "selected"; } ?>>01</option>

          <option value="2" <? IF($_GET['month'] == "2"){ echo "selected"; } ?>>02</option>

          <option value="3" <? IF($_GET['month'] == "3"){ echo "selected"; } ?>>03</option>

          <option value="4" <? IF($_GET['month'] == "4"){ echo "selected"; } ?>>04</option>

          <option value="5" <? IF($_GET['month'] == "5"){ echo "selected"; } ?>>05</option>

          <option value="6" <? IF($_GET['month'] == "6"){ echo "selected"; } ?>>06</option>

          <option value="7" <? IF($_GET['month'] == "7"){ echo "selected"; } ?>>07</option>

          <option value="8" <? IF($_GET['month'] == "8"){ echo "selected"; } ?>>08</option>

          <option value="9" <? IF($_GET['month'] == "9"){ echo "selected"; } ?>>09</option>

          <option value="10" <? IF($_GET['month'] == "10"){ echo "selected"; } ?>>10</option>

          <option value="11" <? IF($_GET['month'] == "11"){ echo "selected"; } ?>>11</option>

          <option value="12" <? IF($_GET['month'] == "12"){ echo "selected"; } ?>>12</option>

        </select>
        <br><br>
        
  <? 
  
function getmicrotime(){ 
    list(
$usec$sec) = explode(" ",microtime()); 
    return ((float)
$usec + (float)$sec); 


$time_start getmicrotime();

IF(!isset(
$_GET['year'])){
    
$_GET['year'] = date("Y");
}
IF(!isset(
$_GET['month'])){
    
$_GET['month'] = date("n")+1;
}

$month addslashes($_GET['month'] - 1);
$year addslashes($_GET['year']);

$todays_date date("j");
$todays_month date("n");

$days_in_month date ("t"mktime(0,0,0,$_GET['month'],0,$_GET['year']));
$first_day_of_month date ("w"mktime(0,0,0,$_GET['month']-1,1,$_GET['year']));
$first_day_of_month $first_day_of_month 1;
$count_boxes 0;
$days_so_far 0;

IF(
$_GET['month'] == 13){
    
$next_month 2;
    
$next_year $_GET['year'] + 1;
} ELSE {
    
$next_month $_GET['month'] + 1;
    
$next_year $_GET['year'];
}

IF(
$_GET['month'] == 2){
    
$prev_month 13;
    
$prev_year $_GET['year'] - 1;
} ELSE {
    
$prev_month $_GET['month'] - 1;
    
$prev_year $_GET['year'];
}
?>
<center>
<table width="330" border="0" align="middle" cellpadding="0" cellspacing="0" bgcolor="#000000">
  <tr>
    <td><table width="330" border="0" cellpadding="0" cellspacing="1">
        <tr class="topdays"> 
          <td><div align="center">Su</div></td>
          <td><div align="center">Mo</div></td>
          <td><div align="center">Tu</div></td>
          <td><div align="center">We</div></td>
          <td><div align="center">Th</div></td>
          <td><div align="center">Fr</div></td>
          <td><div align="center">Sa</div></td>
        </tr>
        <tr valign="top"> 
        <?
        
for ($i 1$i <= $first_day_of_month-1$i++) {
            
$days_so_far $days_so_far 1;
            
$count_boxes $count_boxes 1;
            echo 
"<td width=\"45\" height=\"20\" class=\"beforedayboxes\" bgcolor=\"$table\"></td>\n";
        }
        for (
$i 1$i <= $days_in_month$i++) {
               
$days_so_far $days_so_far 1;
                
$count_boxes $count_boxes 1;
            IF(
$_GET['month'] == $todays_month+1){
                IF(
$i == $todays_date){
                    
$class "highlighteddayboxes";
                } ELSE {
                    
$class "dayboxes";
                }
            } ELSE {
                IF(
$i == 1){
                    
$class "highlighteddayboxes";
                } ELSE {
                    
$class "dayboxes";
                }
            }
            echo 
"<td width=\"45\" height=\"20\" class=\"$class\">\n";
            
$link_month $_GET['month'] - 1;
            echo 
"<div align=\"right\"><span class=\"toprightnumber\">\n $i<input type=\"checkbox\" name=\"checkbox[]\" value=\"$i\">&nbsp;</span></div>\n";
            echo 
"</td>\n";
            IF((
$count_boxes == 7) AND ($days_so_far != (($first_day_of_month-1) + $days_in_month))){
                
$count_boxes 0;
                echo 
"</TR><TR valign=\"top\">\n";
            }
        }
        
$extra_boxes $count_boxes;
        for (
$i 1$i <= $extra_boxes$i++) {
            echo 
"<td class=\"afterdayboxes\"></td>\n";
        }
        
$time_end getmicrotime();
        
$time round($time_end $time_start3);
        
?>
        </tr>
      </table></td>
  </tr>
</table>
<br><br>
</center>


          
         <select name="year" id="year">

          <option value="2008" <? IF($_GET['year'] == "2008"){ echo "selected"; } ?>>2008</option>

          <option value="2009" <? IF($_GET['year'] == "2009"){ echo "selected"; } ?>>2009</option>

          <option value="2010" <? IF($_GET['year'] == "2010"){ echo "selected"; } ?>>2010</option>

          <option value="2011" <? IF($_GET['year'] == "2011"){ echo "selected"; } ?>>2011</option>

          <option value="2012" <? IF($_GET['year'] == "2012"){ echo "selected"; } ?>>2012</option>

        </select><br> </td>

    </tr>
<br>
    <tr> 

      <td width="200" height="40" valign="top"><span class="addevent"><br>Amount of Time</span><br> 

        <span class="addeventextrainfo"></span></td>

      <td height="40" valign="top"> <br><input name="hour" type="text" id="hour" value="00" size="2" maxlength="2">

        : 

        <input name="minute" type="text" id="minute" value="00" size="2" maxlength="2"> 

      </td>

    </tr>

    <tr> 
      <td width="200" height="40" valign="top"><span class="addevent">Event Title</span></td>
      <td height="40" valign="top"> <select name="title">
      <option value="Cardiovascular">Cardiovascular</option>
      <option value="Flexibility">Flexibility</option>
      <option value="Muscular">Muscular</option>
      </select> 
      </td>
    </tr>
    <tr> 
      <td width="200" height="40" valign="top"><span class="addevent">Event Description</span></td>
      <td height="40" valign="top"> <textarea name="description" cols="18" rows="5" id="description"></textarea> 
      </td>
    </tr>
    <tr> 
      <td width="200">&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>        
      <td><input name="submit" type="submit" id="submit" value="Add Event"></td>
    </tr>
  </table>
</form>
</body>
</html>
<? 

?>

i am trying to use an array, but obviously i am doing something wrong