活动日历未显示2月

时间:2016-03-30 09:14:10

标签: php mysql calendar

我正在为我的网站创建一个活动日历,我使用了this tutorialthis other one,以及未知幽灵的youtube教程。

然而,当我进入一个事件时,它会成功但不会变成蓝色。

  1. 我是否犯了一个错误/拼写错误,可以解释为什么它不变蓝?

  2. 此外,一旦添加了一个事件,它就会显示在底部,但如果我刷新页面,事件会自动再次添加。

  3. 每个月都要度过,并意识到二月没有出现。这是为什么?

  4. 这是我的代码:

    calendar.php

    <?php 
    include("functions.php")
    ?>
    <html>
     <head>
      <title>Event Calendar</title>
      <script>
       function goLastMonth(month, year){
        if(month == 1) {
         --year;
         month = 13;
        }
        --month
        var monthstring = ""+month+"";
        var monthlength = monthstring.length;
        if(monthlength <=1){
         monthstring = "0"+monthstring;
        }
        document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
       }
       function goNextMonth(month, year){
        if(month == 12) {
         ++year;
         month = 0;
        }
        ++month
        var monthstring = ""+month+"";
        var monthlength = monthstring.length;
        if(monthlength <=1){
         monthstring = "0"+monthstring;
        }
        document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+monthstring+"&year="+year;
       }
      </script>
      <style>
        .today{
          background-color: #00ff00;
        }
        .event{
          background-color: #0000ff;
        }
      </style>
     </head>
    <body>
    
      <?php
       //get current date or specific month and year
       if (isset($_GET['day'])){
        $day = $_GET['day'];
       } else {
        $day = date("d");
       }
       if(isset($_GET['month'])){
        $month = $_GET['month'];
       } else {
        $month = date("m");
       }
       if(isset($_GET['year'])){
        $year = $_GET['year'];
       }else{
        $year = date("Y");
       }
    
       //get date data for display such as month name
       $currentTimeStamp = strtotime( "$day-$month-$year");
       $monthName = date("F", $currentTimeStamp);
       //get the number of days in the current month and year
       $numDays = date("t", $currentTimeStamp);
       //keep track of the number of cell created
       $counter = 0;  
       ?>
       <?php
       if(isset($_GET['add'])) {
           $name = $_POST['Event_Name'];
           $details = $_POST['Details'];
           $date = $day."/".$month."/".$year;
           $location = $_POST['Location'];
           $staffrq = $_POST['Staff_Required'];
           $cadetsrq = $_POST['Cadets_Required'];
          //insert into database
           $sqlinsert = "INSERT INTO Event_Detail (Event_Name, Details, Date, Location, Staff_Required, Cadets_Required) VALUES 
           ('".$name."', '".$details."', '".$date."', '".$location."', '".$staffrq."','".$cadetsrq."')";
           $resultinsert = mysql_query($sqlinsert);
           if($resultinsert) {
             echo "Event Successfully Added...";
           }else{
             echo "Event Failed to be Added...";
           }
         }
      ?>
    
      <table border="1px">
       <tr>
        <td align="center">
         <input style='width:80px;' type='button' value='<'name='previousbutton' onclick ="goLastMonth(<?php echo $month.','.$year?>)">
        </td>
        <td align="center" colspan="5"><?php echo $monthName." ".$year; ?></td>
        <td align="center">
         <input style='width:80px;' type='button' value='>'name='nextbutton' onclick ="goNextMonth(<?php echo $month.','.$year?>)">
        </td>
       </tr>
       <tr>
        <td align="center" width='80px'>Monday</td>
        <td align="center" width='80px'>Tuesday</td>
        <td align="center" width='80px'>Wednesday</td>
        <td align="center" width='80px'>Thursday</td>
        <td align="center" width='80px'>Friday</td>
        <td align="center" width='80px'>Saturday</td>
        <td align="center" width='80px'>Sunday</td>
       </tr>
       <tr align="center">
    
         <?php
              for($i = 1; $i < $numDays+1; $i++, $counter++){
          $timeStamp = strtotime("$i-$month-$year");
    
          //create empty cell until first day of the month
          if($i == 1) {
           //0=sun, 1=mon, 2=tue, ...
           $firstDay = date("w", $timeStamp);
    
           //if sunday change the firstDay to 7
           if($firstDay == 0)
           $firstDay = 7;
    
           //decrement firstDay by 1
           $firstDay--;
    
           for($j = 0; $j < $firstDay; $j++, $counter++) {
            echo "<td>&nbsp;</td>";
           }
          }
    
          //create new row
          if($counter % 7 == 0) {
           echo"</tr><tr>";
          }
          $monthstring = $month;
          $monthlength = strlen($monthstring);
          $daystring = $i;
          $daylength = strlen($daystring);
          if($monthlength <=1){
            $monthstring = "0".$monthstring;
          }
          if($daylength <=1) {
            $daystring = "0".$daystring;
          }
          $todaysDate = date("d/m/Y");
          $dateToCompare = $daystring.'/'.$monthstring.'/'.$year;
          //print day number
          echo "<td align='center'";
          if ($todaysDate == $dateToCompare) {
            echo "class='today'";
          }else{
            $sqlCount = "SELECT * FROM Event_Detail WHERE Date='".$dateToCompare."'";
            $noOfEvent = mysql_num_rows(mysql_query($sqlCount));
            if($noOfEvents >=1) {
              echo "class='event'";
            }
          }
          echo "><a href='".$_SERVER['PHP_SELF']."?day=".$daystring."&month=".$monthstring."&year=".$year."&v=true'>".$i."</a></td>";
         }
    
    
         //fill up the leftover cells of the table
         while($counter % 7 != 0) {
          echo "<td>&nbsp;</td>";
          $counter++;
         }
        ?>
       </tr>
      </table>
    
         <?php
         if(isset($_GET['v'])){
           echo "<a href='".$_SERVER['PHP_SELF']."?day=".$day."&month=".$month."&year=".$year."&v=true&f=true'>Add Event</a>";
           if(isset($_GET['f'])){
             include("eventform.php");
           }
           $sqlEvent = "SELECT * FROM Event_Detail WHERE Date='".$day."/".$month."/".$year."'";
           $resultEvents=mysql_query($sqlEvent);
           echo "<hr>";
           while($events=mysql_fetch_array($resultEvents)){
             echo "Event Name: ".$events['Event_Name']."<br>";
             echo "Details: ".$events['Details']."<br>";
             echo "Date: ".$events['Date']."<br>";
             echo "Location: ".$events['Location']."<br>";
             echo "Staff Required: ".$events['Staff_Required']."<br>";
             echo "Cadets Required: ".$events['Cadets_Required']."<br>";
           }
         }
         ?>
         </body>
    </html>
    

    eventform.php

    <title>Event</title>
     <form name="eventform" method="POST" action="<?php $_SERVER['PHP_SELF']; ?  >?day=<?php echo $day;?>&month=<?php echo $month;?>&year=<?php echo $year;? >&v=true&add=true">
      <table width="400px">
       <tr>
      <td width="150px">Event Name</td>
      <td width="250px"><input type="text" name="Event_Name" required></td>
    </tr>
    <tr>
      <td width="150px">Details</td>
      <td width="250px"><textarea name="Details" required></textarea></td>
    </tr>
    <tr>
      <td width='150px'>Location</td>
      <td width='250px'><textarea name="Location" required></textarea></td>
    </tr>
    <tr>
      <td width='150px'>Staff Required</td>
      <td width='250px'><input type='number' name="Staff_Required" required></td>
    </tr>
    <tr>
      <td width='150px'>Cadets Required</td>
      <td width='50px'><input type='number' name="Cadets_Required" required></td>
    </tr>
    <tr>
      <td colspan='2' align='center'><input type='submit' name='btnadd' value='Add Event'></td>
    </tr>
    

0 个答案:

没有答案