我有一个预订表格,用户可以预订不同的设施,但我无法理解如何阻止用户预订今天之前的日期或如何防止他们双重预订。
我确实尝试过使用datepicker,但我使用的是HTML5标准的datepicker,还使用了Twitter Bootstrap,但我不知道如何限制用户的日期。
下面包括我的完整表格和其中包含的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 :(得分:1)
要检查某个日期是否在特定日期之前,您可以将日期转换为时间戳,并检查一个日期是否低于另一个
$start_date = $_POST['start_date'];
if( strtotime($start_date) < time()) {
// Date is before today
} else {
// Date is after today
}