Calender with checkbox: How to insert information into database from checkbox
<p>I am trying to create a calender with a checkbox for each date. When a user clicks the submit button, I want to get those selected dates inserted into the database and those which are not selected would be deleted from the database if those already exist before. I have created a index.php page where I wrote the following code to generate dates: </p>

<p>index.php:</p>

<pre><code>&lt;form name="form1" method="post" action="show.php"&gt;
  &lt;?php
    $year="2011";
    $month="8";
    $d=cal_days_in_month(CAL_GREGORIAN,1,2011);

    $i=1;
    while($i&lt;=$d)
    {
  ?&gt;
  &lt;input type="checkbox" name="date[]" value="&lt;? echo  " $year-$month- " . $i . ""."&lt;br&gt;";  ?&gt;"&gt; 
  &lt;? echo  " $year-$month- " . $i . ""."&lt;br&gt;";  ?&gt;
  &lt;?
        $i++;
    }

  ?&gt; 
  &lt;input type="submit" name="Submit" value="Submit"&gt;
  &lt;/form&gt;
</code></pre>

<p>show.php:</p>

<pre><code>&lt;? 
    mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error()); 
    mysql_select_db("database"); 
    $media_array = $_POST['date']; 
    foreach ($media_array as $one_media) 
    {
        $source .= $one_media.", "; 
    } 
    $media = substr($source, 0, -2); 
    $query = "INSERT INTO table1 (id,media) VALUES('', '$media')";
    $result = mysql_query($query); } 
?&gt;
</code></pre>

<p>And then I created page another page named show.php where I tried to write codes for inserting information, but I failed.
Would you please kindly help me to do this? I have tried my best but I couldn't make it happened. Thanks in advance.</p>
