I have made a page where the user books the room.The details of booking is sent to another page where i have insert query.I tried the code for checking the overlapping & printing the alert message on the main booking page but the query isn't working.Please help!
$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());
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…