防止重复预订和今天之前的预订 php pdo
Preventing double booking and booking before today php pdo
我设置了一个预订表格,用户可以在其中预订不同的设施,但我无法理解如何防止用户预订今天之前的日期或如何防止他们重复预订。
我确实尝试过使用日期选择器,但我使用的是 HTML5 标准日期选择器,还使用 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";
}
}
?>
要检查日期是否早于特定日期,您可以将日期转换为时间戳并检查一个日期是否低于另一个日期
$start_date = $_POST['start_date'];
if( strtotime($start_date) < time()) {
// Date is before today
} else {
// Date is after today
}
我设置了一个预订表格,用户可以在其中预订不同的设施,但我无法理解如何防止用户预订今天之前的日期或如何防止他们重复预订。
我确实尝试过使用日期选择器,但我使用的是 HTML5 标准日期选择器,还使用 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";
}
}
?>
要检查日期是否早于特定日期,您可以将日期转换为时间戳并检查一个日期是否低于另一个日期
$start_date = $_POST['start_date'];
if( strtotime($start_date) < time()) {
// Date is before today
} else {
// Date is after today
}