php - Check for time overlap in mysql -
i have made page user books room.the details of booking sent page have insert query.i tried code checking overlapping & printing alert message on main booking page 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 * roomdetails (date=$date , (endtime > '" . $btime . "') , (starttime < '" . $etime . "'))"; if($a == true) { echo '<script language="javascript">'; echo 'alert("please select time slot")'; echo '</script>'; } else { $sql="insert 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()); }
the condition $a==true
true since "$a" string , not empty.
i suggest fire query , check result , might succeed.
Comments
Post a Comment