防止重复预订和在今天之前预订php pdo
我设置了一个预订表单,用户可以预订不同的设施,但我不知道如何防止用户预订今天之前的日期,或者如何防止他们重复预订 我确实尝试过使用日期选择器,但我使用的是HTML5标准日期选择器,也使用Twitter引导,但我不知道如何限制用户的日期 下面是我的完整表单和其中包含的PHP防止重复预订和在今天之前预订php pdo,php,twitter-bootstrap,pdo,Php,Twitter Bootstrap,Pdo,我设置了一个预订表单,用户可以预订不同的设施,但我不知道如何防止用户预订今天之前的日期,或者如何防止他们重复预订 我确实尝试过使用日期选择器,但我使用的是HTML5标准日期选择器,也使用Twitter引导,但我不知道如何限制用户的日期 下面是我的完整表单和其中包含的PHP <?php include "config.php"; //Booking point if(isset($_POST['booking'])) {
<?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
}
$start\u date=$\u POST['start\u date'];
if(strotime($start_date)
缩小您的代码以isset(['booking'])开头的代码开始我的预订过程。使用“缩小您的代码”我的意思是我们不需要所有的htmlOh。没问题,对不起。在插入新预订之前立即编辑。您需要从以前的预订中获取日期。一旦你有了这些,你就可以将它们与新预订进行比较。如果新预订与以前的任何预订不匹配,您可以插入新预订