Show alert if unavailable slot within the time range [closed]

As stated above, i would like to appear alert when unavailable slot query from SQL , below the code were not working .

$starttime = date("H:m:s", strtotime($_POST['start_time']));
$endtime = date("H:m:s", strtotime($_POST['end_time']));

function createOrder(){

  global $dbconnection;

  $date = $_POST['order_date'];
  $starttime = date("H:m:s", strtotime($_POST['start_time']));
  $endtime = date("H:m:s", strtotime($_POST['end_time']));
  $room = $_POST['room'];

  $dataQ = mysqli_query($dbconnection,"SELECT * FROM `booking`");

  $sql = "INSERT INTO `booking_slot`.`booking`(
      `name`,
      `department`,
      `order_date`,
      `start_time`,
      `end_time`,
      `room`,
      `purpose`)
      VALUES (
          '{$_POST['name']}',
          '{$_POST['department']}',
          '{$_POST['order_date']}',
          '{$_POST['start_time']}',
          '{$_POST['end_time']}',
          '{$_POST['room']}',
          '{$_POST['message']}')";
  ;

  while($row = mysqli_fetch_assoc($dataQ)){
      if($row['order_date'] == $date && ($row['start_time'] >= $starttime && $row['end_time'] <= $endtime) && $row['room'] == $room){
          echo '<script>';
          echo 'window.location.href="booking.php";';
          echo 'alert("someone is taken the slot, pls try again !");';
          echo '</script>;';
      }
       else {
               mysqli_query($dbconnection,$sql);
               header("Location: booking-completed.php");
           }
  }
  
}
?>

enter image description here

Expect if date, time range and room is matched show the alert , appreciate kind assistance on this , TQ !