I have a table "events" which has columns "start_time", "end_time" of datatype "time" which stores value such as "11:30:00". The rule is that no event should have a overlap time. So, if for one day there is already an event from 8AM to 10AM, then a new event could not start earlier than 10AM. I think the following code should be able to do this checking, but it didn't work. Can someone please help me correct it.
$input_day = $POST["input_day"];
$input_start_time = $POST["input_start_time"]; //a string like "9:00:00"
$input_end_time = $_POST["input_end_time"]; //a string like "10:00:00"
$sql = "SELECT start_time, end_time from events where the_day = $input_day";
$result = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_assoc($result)) {
$existing_event_start_time = row["start_time"];
$existing_event_end_time = row["end_time"];
if ($input_start_time > $existing_event_end_time || $input_end_time > $existing_event_start-time) {
print "sorry, this time slot already taken";
//code to send user back to the input page
}
}