Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8156377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:56:10+00:00 2026-06-06T16:56:10+00:00

I have a website where users can purchase tickets, but ticket quantities are usually

  • 0

I have a website where users can purchase tickets, but ticket quantities are usually limited and go quickly. I’m trying to implement an escrow system such that a user can click that they want x number of tickets, at which point I will put them in an escrow state. That gives them several minutes to enter their credit card information and complete the purchase.

I have three relevant tables: events, tickets, and escrow. A row in the events table describes the event itself, including the maximum number of tickets available.

The tickets table holds the following:

user_id: the user that purchased the tickets

number_of_tickets: how many tickets they purchased

event_id: the relevant event

The escrow table holds the following:

user_id: the user in the process of purchasing tickets

number_of_tickets: how many tickets they want

event_id: the relevant event

Currently, I do three MySQL queries, one for the max tickets, one for the number of tickets sold, and one for the number of tickets already in escrow. Then I calculate:

$remaining_tickets = $max_tickets - $tickets_sold - $tickets_in_escrow;
if ($remaining_tickets >= $tickets_desired)
{
    beginEscrow($user_id, $event_id, $tickets_desired);
}
else
{
    echo "Error:  not enough ticket remain.";
}

My problem is that it is possible for more than one user to be executing this code at the same time. If one user were to call beginEscrow after another user had already read the number of tickets already in escrow, it’s possible that I’ll oversell the show.

I’m using the InnoDB engine for my tables, and I’ve read how to lock a single row by using SELECT .... FOR UPDATE, but I’m not updating a single row. The beginEscrow function will just insert a new row into the escrow table. I calculate $tickets_in_escrow by reading all rows with the correct event id and adding up the number of tickets in each of them.

Maybe I’m going about it all wrong?

Do I need to lock the entire table?

I can’t be the first one to write a ticket escrow system. I’ve googled myself to death trying to find some tutorial on this kind of thing, but struck out. Any ideas would be helpful.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:56:13+00:00Added an answer on June 6, 2026 at 4:56 pm

    You are very close on your design, but not quite there.

    First of all, your event table needs to hold the number of tickets still available for your event (in addition to whatever else you want there).

    Second, your escrow table needs to have a DATETIME column indicating when the escrow expires. You need to set that value whenever tickets go into escrow.

    Third, the transaction of putting tickets in escrow needs to

    1. lock the event row.
    2. read the available tickets column. (abort if not enough are available)
    3. insert a row in the escrow table
    4. update the event row to decrement the available tickets column.
    5. unlock the event row.

    Fourth, the action of completing the sale needs to delete the escrow row and insert a sold-ticket row. This isn’t hard.

    Fifth, you need an escrow cleanup operation. This needs to look for all escrow rows that have expired (that have an expiration date in the past) and, for each one:

    1. lock the corresponding event row.
    2. read the number of escrowed tickets from the escrow table
    3. delete the escrow table row.
    4. update the event row to increment the available tickets column.
    5. unlock the event row.

    The trick is to have the number of available tickets maintained in a way that is interlocked correctly, so race conditions between users don’t oversell your event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website where users can upload files to share with others. But
I have website where users can login with their Facebook account. I am using
I have a website for dance academy where Users can register and add/drop dance
I have multiple themes on my website and users can just switch between multiple
I want to create a website with various users. The users can have different
So, I have a user driven website. Users can post whatever they want, even
I have a website which users can sign up to using Facebook Connect (with
I have a website where users can send their RICH text description. I'm using
I have a website the users can do stuff like leave comments, perform likes,
I have a website were users can create a profile and upload an image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.