473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Code to prevent a double booking

1
Hi,

I am creating a website for a project where you are able to book driving lessons.

I have created code which (sort of) prevents double booking, however, I'm having a problem.

If there is a booking stored in the DB at 11.30-12.30, if i try to book a lesson from 11-12 it prevents me from doing so, however if I try book from 12-1, it allows me to go ahead with the booking.

The code I am using is below. Does anyone know how to solve this error? Thanks!


Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include('../config.php'); 
  4. $Name = '';
  5. $LessonDate = '';
  6. $StartTime = '';
  7. $EndTime = '';
  8. if (isset($_POST['submit'])) { 
  9. if(isset($_POST['Name'])){ $Name = $_POST['Name']; }
  10. if(isset($_POST['LessonDate'])){ $LessonDate = $_POST['LessonDate']; }
  11. if(isset($_POST['StartTime'])){ $StartTime = $_POST['StartTime']; }
  12. if(isset($_POST['EndTime'])){ $EndTime = $_POST['EndTime']; }
  13.  
  14.  
  15. $result = mysql_query("SELECT * FROM booking WHERE LessonDate = '".mysql_real_escape_string($LessonDate)."' AND (StartTime >= '".mysql_real_escape_string($StartTime)."' AND StartTime <= '".mysql_real_escape_string($EndTime)."')");
  16. if(!$result)
  17. {
  18.     die(mysql_error());
  19. }
  20.  
  21. if(mysql_num_rows($result) > 0)
  22. {
  23.     die('<p>This date and time have already been booked. <a href="http://bytes.com/booking1.php">Please try another time</a>.</p>');
  24. }
  25. else
  26. {
  27.     //insert new user data into Users table
  28. $sql = "INSERT INTO `booking` ( `Name`, `LessonDate` ,  `StartTime` ,  `EndTime`  ) VALUES(  '{$Name}', '{$LessonDate}' ,  '{$StartTime}' ,  '{$EndTime}') "; 
  29. mysql_query($sql) or die(mysql_error());
  30. echo "Booking Successful.<br />"; 
  31. echo "<a href='http://bytes.com/text.php'> Send reminder text </a>"; 
  32. }
  33.  
  34. } ?>
Feb 17 '13 #1
1 4261
Rabbit
12,516 Expert Mod 8TB
To see if time range A overlaps with time range B, you need to check if A's start is before B's end AND A's end is after B's start. If both are true, then the range overlaps.
Feb 17 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Grant | last post by:
Hi I have a database which logs the usage of rooms. Some booking are entered well in advance, and some have stays of more than six months. I would like to ensure that rooms which have been...
50
by: johnblack | last post by:
I am creating a tennis court booking system. I am trying to create a macro that will not allow the same court to be booked on the same date at the same time. I have the following tables and...
5
by: ugcs93 | last post by:
I'm a self taught beginner and, with a lot of luck, I've managed to build a db to schedule classes, rooms, and students. But I'm stuck on ensuring students aren't double booked. I assigned a code...
3
by: anotherjoe | last post by:
Question 1: I have reservation database in access 2007 I have a cabin information table with: cabinid (primarykey) cabinname(text) cabinlocation(text) I have a customer table with:...
3
by: Keyboyx | last post by:
I am creating a Dentist Booking form, for my A level project. I have the following Tables: Appointments Appointment ID Dentist ID Patient ID Appointment Date Appointment Time
1
by: alexseow | last post by:
How to prevent double login with same account? , hv any ideas? thanks
3
by: Wayne | last post by:
I'm building a bookings database for trucks that among other things captures the TruckName, LoadDate, LoadTime, UnloadDate and UnloadTime. Is there a simple way to prevent double bookings for any...
1
by: Jordan Boden | last post by:
Hi, I have a problem trying to prevent a time slot and seat number being double booked. I am using PHP and MySQL for this. Currently I have no errors concerning variable names or issues with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.