开发者

Ticket Reservation System Using PHP Implementation

开发者 https://www.devze.com 2023-03-10 12:38 出处:网络
How to prevent a seat from being booked twice in a reservation system? I am making a model reservation system for air travel in PHP and MYSQL as a project. I have a small problem.

How to prevent a seat from being booked twice in a reservation system?

I am making a model reservation system for air travel in PHP and MYSQL as a project. I have a small problem. Here ticket and seat details are stored permanently only after payment. Seat number is assigned before payment.

Suppose person 1 books seat x on a plane and pay开发者_如何学Cs for it.

While still person 1 is still paying for the ticket, person 2 books the same seat (seat has not yet been reserved) and completes payment first..

Now both people will have booked the same seat..

Can someone tell me how to implement a temporary booking storage that can be used to store data while booking occurs and is accessible by other users to solve this problem and the data should be deleted automatically as soon as the user's session is over to prevent fake reservations. Please give a reply ASAP.


As soon as a user selects a seat you should should record that a seat and ticket is being held, probably in a separate table along with a timestamp of when this action occured, as well as the user's id/session id.

When you get for available seats you should check your bookings table and the temporary seat/ticket table to figure our what seats are available. When a user books a ticket you can add the permanent reservation to your booking table and then remove the entry from the temporary table.

You will probably want to have a scheduled operation that deletes all temporary entries that are # of minutes old.

The fastest way to do something like this would be to have an in memory cache of temporary bookings, such as memcache, or a global object, however you will still have to deal with thread/synchronization and race conditions.


When you design the DB there should be a flag for already booked If it is yes no can book it again. Just add a checking based on that db field

the guy who set the booking should be able to cancel the booking . There should be a log too. The userid should be linked to that ticket anyway so that the user can update later even if anything happen in between booking.

you can use Commit Rollback in db transactions


If I were doing it, I'd implement it in the database.

have a bookedtime field, and a status field.

When someone selects that registration booking, add a record to the table; this record prevents anyone else from selecting that booking. (INSERT INTO bookings(some,fields,bookedtime,status) VALUES('quack','moo',NOW(),0) )

Whenever someone indicates they're in the process of booking that slot (IE: Every time they page reload in the same session, moving through the checkout process), update the table. (UPDATE bookings SET bookedtime = NOW() WHERE somefield = 'someidentifier';)

Every X minutes, cron the database with "DELETE FROM bookings WHERE status = 0 AND bookedtime < CURRENT_TIME - INTERVAL 15 MINUTE".

Refer this link

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号