我尝试了多种方法来做到这一点,我只是在智慧结束。 我正在尝试检查飞机预订日历中特定日期的重叠时间。
这是我的表格:
<form action="add-schedule.php" method="post">
Aircraft:<BR>
<input type="text" value="<?php echo $_GET["air"]; ?>" name="aircraft" readonly><BR><BR>
Pilot in Command:<BR>
<input type="text" value="<?php echo $user; ?>" name="user" readonly><BR><BR>
Date:<BR>
<input type="text" value="<?php echo date('Y-m-d', strtotime($_GET["dt"])); ?>" name="dt" readonly><BR><BR>
Start Time:<BR>
<input type="time" name="tm" required><BR><BR>
End Time:<BR>
<input type="time" name="et" required><BR><BR>
<input type="submit"><BR><BR>
</form><BR>
这是我的添加文件:
<?php
include('connect.php');
$name = mysqli_real_escape_string($con, $_POST['aircraft']);
$user = mysqli_real_escape_string($con, $_POST['user']);
$dt = mysqli_real_escape_string($con, $_POST['dt']);
$tm = mysqli_real_escape_string($con, $_POST['tm']);
$et = mysqli_real_escape_string($con, $_POST['et']);
$TM = date('H:i:s', strtotime($tm));
$ET = date('H:i:s', strtotime($et));
if ($result = $con->query("SELECT * FROM cal WHERE ( '$TM' BETWEEN cal_time
AND cal_end) OR ('$ET' BETWEEN cal_time AND cal_end) OR (cal_time < '$TM'
AND cal_end > '$ET') AND cal_date = '$dt' AND cal_air = '$name'"))
{
if ($result->num_rows > 0)
{
header("location:add-sched-error.php");
}
}
$sql = "INSERT INTO cal (cal_air, cal_user, cal_date, cal_time, cal_end)
VALUES('$name', '$user', '$dt', '$tm', '$et')";
if (!mysqli_query($con, $sql))
{
die('Error: '.mysqli_error($con));
}
header("location:aircraft-schedule.php");
mysqli_close($con);
?>
我在这里缺少什么?
修改 编辑OP以使问题更清晰。 (删除了var_dump结果)
答案 0 :(得分:0)
我尝试使用您的代码和测试数据库,除了OR
和AND
查询中SELECT
和if ($result = $con->query("SELECT * FROM cal WHERE ( ( '$TM' BETWEEN cal_time
AND cal_end) OR ('$ET' BETWEEN cal_time AND cal_end) OR (cal_time < '$TM'
AND cal_end > '$ET') ) AND cal_date = '$dt' AND cal_air = '$name'"))
{
if ($result->num_rows > 0)
{
header("location:add-sched-error.php");
}
}
的组合之外,它几乎可以使用。将时间检查包含在一组额外的括号中为我工作:
import operator
from zeep import Client
wsdl = 'http://www.soapclient.com/xml/soapresponder.wsdl'
client = Client(wsdl=wsdl)
for service in client.wsdl.services.values():
print "service:", service.name
for port in service.ports.values():
operations = sorted(
port.binding._operations.values(),
key=operator.attrgetter('name'))
for operation in operations:
print "method :", operation.name
print " input :", operation.input.signature()
print " output:", operation.output.signature()
print
print