php - Mysqli query is not returning anything when attempting to filter duplicate times on the same day -


i have attempted multiple ways , @ wits end. trying check overlapping times on specific date aircraft reservation calendar.

here form:

<form action="add-schedule.php" method="post">             aircraft:<br>             <input type="text" value="<?php echo $_get["air"]; ?>" name="aircraft" readonly><br><br>             pilot in command:<br>             <input type="text" value="<?php echo $user; ?>" name="user" readonly><br><br>             date:<br>             <input type="text" value="<?php echo date('y-m-d', strtotime($_get["dt"])); ?>" name="dt" readonly><br><br>             start time:<br>             <input type="time" name="tm" required><br><br>             end time:<br>             <input type="time" name="et" required><br><br>             <input type="submit"><br><br>             </form><br> 

here add file:

    <?php     include('connect.php');      $name = mysqli_real_escape_string($con, $_post['aircraft']);     $user = mysqli_real_escape_string($con, $_post['user']);     $dt = mysqli_real_escape_string($con, $_post['dt']);     $tm = mysqli_real_escape_string($con, $_post['tm']);     $et = mysqli_real_escape_string($con, $_post['et']);     $tm = date('h:i:s', strtotime($tm));     $et = date('h:i:s', strtotime($et));      if ($result = $con->query("select * cal ( '$tm' between cal_time  , cal_end) or ('$et' between cal_time , cal_end) or (cal_time < '$tm'  , cal_end > '$et') , cal_date = '$dt' , cal_air = '$name'"))     {         if ($result->num_rows > 0)         {              header("location:add-sched-error.php");         }      }      $sql = "insert cal (cal_air, cal_user, cal_date, cal_time, cal_end)      values('$name', '$user', '$dt', '$tm', '$et')";      if (!mysqli_query($con, $sql))     {         die('error: '.mysqli_error($con));     }     header("location:aircraft-schedule.php");      mysqli_close($con);     ?> 

what missing here?

edit edited op make question more clear. (removed var_dump results)

i did playing around code , test database, pretty works except combination of or , and in select query. wrapping time check in set of parentheses worked me:

if ($result = $con->query("select * cal ( ( '$tm' between cal_time  , cal_end) or ('$et' between cal_time , cal_end) or (cal_time < '$tm'  , cal_end > '$et') ) , cal_date = '$dt' , cal_air = '$name'")) {     if ($result->num_rows > 0)     {          header("location:add-sched-error.php");     }  } 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -