我尝试了不同的方法来验证日期是否存在于现有日期本身以及数据库中的日期范围,但它根本不起作用。编码将忽略查询并让用户成功预订资产。
这是我的数据库的图像:
<?php
session_start();
include("dbFunctions.php");
$message = "";
if (isset($_POST['end_date'])) {
//retrieve form data
$endd1 = $_POST['end_date'];
$startd1 = $_POST['start_date'];
$assetID = $_POST['asset_id'];
//check if start date and end date range entered exists within database record
$query = "SELECT * FROM booking WHERE booking.asset_id = '$assetID' AND ('$startd1' BETWEEN booking.start_date AND booking.due_date) AND ('$endd1' BETWEEN booking.start_date AND booking.due_date) " ;
$result = mysqli_query($link, $query) or die(mysqli_error($link));
if (mysqli_num_rows($result) == 1) {
$exists = true;
} else {
$exists = false;
}
} else {
$msg .= 'Sorry, Please enter another date.';
$msg .= '<br/>';
$msg .= '<a href="addBooking.php">Please try again.</a>';
}