Having trouble with a overlapping times check in my query...

So I have a form that enters a aircraft reservation into the database…
[php]

Aircraft:
" name="aircraft" readonly>

Pilot in Command:


Date:
" name="dt" readonly>

Start Time:


End Time:





[/php]

and when you submit it it passes the info to the next file…

[php]

<?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 * FROM cal WHERE ( '$TM' BETWEEN cal_time AND cal_end) OR ('$ET' BETWEEN cal_time AND cal_end) OR (cal_time < '$TM' AND cal_end > '$ET') AND cal_date = '$dt' AND cal_air = '$name'")) { if ($result->num_rows > 0) { header("location:add-sched-error.php"); } } $sql = "INSERT INTO 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); ?>

[/php]

but for whatever reason its not catching any overlapping times at all. I have tried multiple examples/ways with no success. I am wondering if its not liking how th form passing dates or times but if so Im not really sure how to fix that either.
the database is using a Date, and Time fields to store the data.
What am I missing?

I developed a trivia game that reset the highscore table based on dates.

Here’s the query for it ->
[php]query = “SELECT * FROM quiz_controller WHERE daily_date >= CURDATE() AND daily_date < DATE_ADD(CURDATE(), INTERVAL 1 DAY)”;[/php]

I would check out -> https://dev.mysql.com/doc/ for it will most likely get you what you need. I know that is what I did. MySQL is quite powerful once you know how to utilize it.

HTH John

Sponsor our Newsletter | Privacy Policy | Terms of Service