Jump to content

Reservation issue


Cauton

Recommended Posts

Hello everyone, and thanks in advance for trying to help me.

 

I'm an IT student in Rotterdam, and I've got a little problem here. It's probably basic to most of you guys, but I've only been working with php for the past 3 months or so.

 

I'm making a website for some company, and they want a reservation system. I've created everything so far, except for the fact that you can actually double book. Can you guys tell me how to make sure you can't book a reservation when that time is used by another reservation? Preferably even, when making the reservation, the reserved times aren't even chooseable.

 

In my database I have the current info:

 

table: reservations

 

id (PK, UQ, A_I)

date (date)

starting time (time example: 09:00:00)

ending time (time example: 10:00:00)

~Some other random information needed by that company~

 

Now it doesn't need to come to minutes or seconds, you can only reserve for whole hours, from and untill the hour.

 

I made the script that puts everything in the database and everything, I just need a little script on how to check if the time on the date you selected earlier (it's like a step system, step 1 select date, step 2 select time, step 3 fill in other random info) is already reserved, and to make sure the reserved times don't appear into the dropdown menu for the times.

 

I hope you guys can help me.

Link to comment
Share on other sites

You need to try a SELECT query on the date/time/whatever it is that would indicate a conflict before attempting to INSERT a new reservation.  Something like (pseudo-code, adjust to fit your needs):

 

$query = "SELECT id FROM reservations WHERE day = $day AND start_time >= $start_time AND end_time <= $end_time";

 

When you run the query, count the number of rows it returns.  If it's >= 1, you have reservation(s) booked already:

 

$result = mysql_query($query);

if (mysql_num_rows($result) >= 1)
{
   // error: something has already been reserved
}
else
{
   // insert new reservation
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.