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:

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

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

                      ?> 
                <input type="submit" name="Submit" value="Submit">
                      </form>

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.

Just check whether your checkboxes are checked or not, and if yes, what their value is? All checkboxes and their values can be found in the $_POST data. :)

The selected dates will be in $_POST as an array of those dates selected. If no dates were checked, $_POST won't exist! So don't just assume an array will be there.

You can store the current month and year in hidden fields in your form. After submission, delete ALL entries for month-year in the database, then insert entries found in the date array.

As your form is now, you will lose past entries if a user updates a month. Existing entries must be read from the database and have their check boxes be checked when you render the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.