防止

2015-04-27 84 views
1

我有一個預訂表格設置,用戶可以預定不同的設施,但我不能讓我圍繞如何防止用戶預訂是在今天之前還是怎麼的日期前頭部今天PHP PDO重複預訂和預訂以防止他們重複預訂。防止

我也試着和一個datepicker工作,但我使用的是HTML5標準的日期選擇器,也使用Twitter的引導,但我不知道如何限制用戶的日期。

下面包含了我完整的形式,幷包含在它的PHP。

<?php 
     include "config.php"; 

     //Booking point 
     if(isset($_POST['booking'])) 
     { 
      //get values for variables 
      $pitchID = $_POST['pitchID']; 
      $start_date = $_POST['start_date']; 
      $start_hour = $_POST['start_hour']; 
      $end_hour = $_POST['end_hour']; 
      $booking_age = $_POST['booking_age']; 
      $pitch_size = $_POST['pitch_size']; 
      $light_tokens = $_POST['light_tokens']; 

      $q = $db->prepare("INSERT INTO booking SET pitchID = ?, start_date = ?, start_hour = ?, end_hour = ?, booking_age = ?, pitch_size = ?, light_tokens = ?"); 
      $query = $q->execute(array($pitchID,$start_date,$start_hour,$end_hour,$booking_age,$pitch_size,$light_tokens)); 

      $count = $q->rowCount(); 
       if($count == 0) 
       { 
        echo "Your booking has been made"; 
        header("Location:home2_template.html"); 
        return; 
       }else { 
        echo "That booking already exists"; 
       } 
     } 

    ?> 
+0

下縮小你的代碼 – SuperDJ

+0

與isset開頭的代碼在某個日期之前([「預訂」])開始我的預訂程序 – Stuart

+0

與「縮小你的代碼」我的意思是,我們不需要所有的HTML – SuperDJ

回答

1

要檢查的日期是,你可以轉換你的日期時間戳,並檢查是否一個比另一個

$start_date = $_POST['start_date']; 

if(strtotime($start_date) < time()) { 
    // Date is before today 
} else { 
    // Date is after today 
}