我已经制作了一个用户预订房间的页面。预订的详细信息被发送到我有插入查询的另一个页面。我尝试了检查重叠和放大的代码。在主预订页面上打印警报消息,但查询无效。请帮助!
$room = mysqli_real_escape_string($conn, $_POST['txtrname']);
$name = mysqli_real_escape_string($conn, $_POST['txtname']);
$purpose = mysqli_real_escape_string($conn, $_POST['txtpurpose']);
$attendee = mysqli_real_escape_string($conn, $_POST['attendee']);
$date = mysqli_real_escape_string($conn, $_POST['txtdate']);
$btime = mysqli_real_escape_string($conn, $_POST['btime']);
$etime = mysqli_real_escape_string($conn, $_POST['etime']);
$a="SELECT * from roomdetails WHERE (date=$date AND (endtime > '" . $btime . "') AND (starttime < '" . $etime . "'))";
if($a == true)
{
echo '<script language="javascript">';
echo 'alert("Please select another time slot")';
echo '</script>';
}
else
{
$sql="INSERT INTO roomdetails(room,name,purpose,attendee,date,starttime,endtime,status_id)VALUES('$room','$name','$purpose','$attendee','$date','$btime','$etime','1')";
}
if (mysqli_query($conn,$sql))
{
echo "Record added";
}
else
{
die('Error: ' . mysqli_error());
}
答案 0 :(得分:1)
条件$a==true
将始终为真,因为“$ a”是一个字符串而非空。
我建议你触发查询,然后检查结果,你可能会成功。