Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
145 views
Welcome To Ask or Share your Answers For Others

1 Answer

The condition $a==true will always be true since "$a" is a string and not empty.

I would suggest you to fire the query and then check the result and you might succeed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...