Hello,
I'm just looking for an answer or idea.
I plan to connect vb.net to mysql (which is done) and also the PHP connected to the mysql.
But I'm confuse with something.

VB.NET is use for offline things (which people will come to store and buy), but PHP is buying / booking online. (You know the airport things right ? customer can directly go to the airport and buy tickets or they can buy tickets from the internet)

For ex :
Customer A come to airport and buy a ticket which is only left 1 tickets. Customer B wanted to buy from the internet. Both of them saw there is only left 1 tickets. So, both of them buying. When Customer A buy, the employee click buy at the same time with Customer B.
In here, I'm confuse, how to declare which person should get the ticket because they click buy at the same time (server time because PHP and MySQL located to the server and vb.net applciation located to other PC/Machine) ?.

So when generating ticket ID, either employee for Cust A or Cust B know that the ticket just bought buy other person.

Sorry If it is a bit confusing, hope you understand.

Dani AI

Generated

Short answer: make the server/database authoritative and perform the availability check and ticket creation as one atomic operation. Client clocks or simultaneous button clicks are irrelevant — the database decides commit order. Desktop and PHP front ends must call the same server-side logic so business rules are enforced in one place.

Two practical, production-ready patterns:

  • Atomic UPDATE + check affected rows (fast, simple): perform a single UPDATE that decrements available seats only when seats > 0, then check the client library's affected_rows/ROW_COUNT(). If the UPDATE affected one row, INSERT the ticket row and commit; otherwise roll back and return "sold out".
  • SELECT ... FOR UPDATE inside a short transaction (safer when multiple fields or complex checks are needed): lock the seat/flight row, re-check availability, decrement and insert, then commit.

Example (illustrative SQL flow):

START TRANSACTION;
UPDATE flights
  SET seats_available = seats_available - 1
  WHERE flight_id = ? AND seats_available > 0;
-- check affected_rows(); if = 1 then
INSERT INTO tickets (flight_id, buyer_id, created_at) VALUES (?, ?, NOW());
COMMIT;
-- else ROLLBACK;

Operational notes and cautions: use InnoDB (transactions and row locks). Keep transactions very short to avoid contention. Handle deadlocks by retrying the transaction a few times. Generate the ticket ID server-side (AUTO_INCREMENT + LAST_INSERT_ID()) only after the successful INSERT; do not pre-generate IDs on the client. Consider a short reservation/hold with expiry for cart-style flows so users get time to finish payment without holding hard locks. Finally, centralize purchase logic behind a secure API (both PHP and the VB.NET client call the same endpoint) rather than opening desktop apps to direct DB access.

Building on 's point about server-side validation, the patterns above give concrete, reliable ways to ensure only one buyer gets the last ticket in the race described by .

Hello,
I'm just looking for an answer or idea.
I plan to connect vb.net to mysql (which is done) and also the PHP connected to the mysql.
But I'm confuse with something.

VB.NET is use for offline things (which people will come to store and buy), but PHP is buying / booking online. (You know the airport things right ? customer can directly go to the airport and buy tickets or they can buy tickets from the internet)

For ex :
Customer A come to airport and buy a ticket which is only left 1 tickets. Customer B wanted to buy from the internet. Both of them saw there is only left 1 tickets. So, both of them buying. When Customer A buy, the employee click buy at the same time with Customer B.
In here, I'm confuse, how to declare which person should get the ticket because they click buy at the same time (server time because PHP and MySQL located to the server and vb.net applciation located to other PC/Machine) ?.

So when generating ticket ID, either employee for Cust A or Cust B know that the ticket just bought buy other person.

Sorry If it is a bit confusing, hope you understand.

So what happens is that VB.NET part, it is a in-store employee's work to get the transaction done while Php one is a web application on www.your-site.com for customer to buy online straight right?

I am glad to say that:
1: VB.NET is still online stuff, as it requires the staff's terminal to go online.
2: The database connection will limit each transaction at a time, meaning which, despite both person clicked on the same time, it is up to database to handle which transaction to be processed first in a split second.
3: You should do a validation part on the database part, and returns an error if the ticket has reached 0. (Something like

'I presume you have the Database connection / Command thing ready
'Step 1: Get the number of tickets left.
dbCommand.CommandText = ""'Code is omitted for simplicity
dbConn.Open() 'Opens a database connection
Dim Qty As Integer = CInt(dbCommand.ExecuteScalar())
If Qty < 0 Then
Return False
Else
'Insert the record of a Customer / Buyer into database
dbCommand.CommandText = "" 'Code is omitted for simplicity
dbCommand.ExecuteNonQuery()
'Another update of the amount of tickets it has right now.
dbCommand.CommandText = "" 'Code is omitted for simplicity
dbCommand.ExecuteNonQuery()
dbConn.Close() 'Close database connection
End IF
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.