Pergunta

I am workinng on a development of online web application in PHP. The system is regarding seats booking system for a travel company. I have a booking form containing a select box which have list of tour code. Whenever a user selects the tour code an Ajax request fetches currently available number of seats for that tour code. After this the user selects the number of seats he requiers to book and fill details of that number of passengers in form and submits the form.

As this system is online a situation may arise as follow:

User1 and user2 has logged in trying to book seats for tourA. For tourA only 10 Seats are available. User1 want to book 7 seats and user2 wants to book 5 seats. Both hit the booking form link and both are getting the available seats number as 10. Both has started filling the form as form is little bit lengthy. Both takes some different time to fill the form and submit according to there typing speed.Both the users are thinking that they will get the required number of seats booked. But both have submit the form with small time difference the one her consider userB submit first will get the booking and the other userA will get the an error message that the respective number of seats are not available. So here userA get confused that as the he got the message that the number seats are availebe now after submitting the form he gets the message require number of seats are not available.

How could I avoid the condition like above? I need the logical flow behind the real time booking system. Anybody please explain me this and how to achive this in php.

I am thinking of as soon as the user selects the number of seats count; using ajax I will update the field in database table which maintains this available number of seats count and book that number of seats for that session. But here a codition may arise like if user selects the seats and start filling the form but due to any reason if he is not submits the booking form then the problem will arise because we have removed required number of seats from db but booking procedure is not completed by user. So how to revert this back as well as we updated the table then the other users who want to book seats they my fond that the number of seats are not available and they will be gone and will not check it again. Due to this travel company's business may goes down.

Please note that every user need to login to application for booking the seats.

Friends you may found this question as home work but here I dont have any firm logical solution. Please guide me in this and please explain me the logical flow of system to overcome above kind of situation. If anybody have a simple code example in PHP for this for reference the it will also helpful for me.

Expecting positive reply

Thank You!

Foi útil?

Solução

There really is not a perfect way to do this. You basically have 3 options

  1. Reserve the resource as soon as the user indicates that they want to reserve it (this what nycballet.com does)
  2. Reserve the resource when the user commits to the purchase(this is what travelocity does).
  3. Let both users purchase the resource and have a facility for a human to rollback one of the transactions (aka overbooking)

Which you pick ultimately is a business decision and one that depends on the shape of your funnel and how sensitive your users are to UX problems.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top