Hey guys...I've run into a little issue (noob here).
I’ve setup a little application for scheduling days + times in different rooms.
I’m trying to implement some sort of an error check which determines is someone has already been scheduled for a certain day, time(range), and certain room. For example:
USER A is scheduled for the following:
Room: happyroom
Day: 2010/01/01
Time From: 10:00am
Time To: 1:00pm
Now USER B should be RESTRICTED from scheduling the following, because there is an overlap in the TIME RANGE, on that day, for that room.
Room: happyroom
Day: 2010/01/01
Time From: 11:00am
Time To: 1:30pm
I thought this might work:
$query = mysql_query("SELECT * FROM schedata WHERE timeFrom BETWEEN '$timeFrom' AND '$timeTo' AND schedate='$schedate AND room='$room'") or die(mysql_error());
if(mysql_num_rows($query)) { // If the query returned any rows
echo "<script>alert('The room has already been reserved for \"$schedate\" from \"$timeFrom\" to \"$timeTo\". Click OK to try another day/time'); location = 'book.php?userid=$userid';</script>";
die;
}else {
$query = "INSERT INTO schedata (ID, userid, schedate, comment, room, today, timeFrom, timeTo) VALUES ('','$userid', '$schedate', '$comment', '$room', '$today', '$timeFrom', '$timeTo')";
mysql_query ($query) or die ('error updating database');
}
But it doesn’t seem to work correctly.
Any suggestions on this?
All the data is being inputed in a form. Users select the TIME FROM and TIME TO from two separate drop downs.
Thanks