PHP/MySQL - Paypal adding and increment from a range

ok i am sure the title is a bit misleading,

what i am trying to do now is setup an add to cart button for paypal, which i have done and it works well in sandbox, what i am struggling with is how to add a ticket number from a range of physical tickets that i want to sell. i have an idea on how to do it but not sure if its the most efficient/safe way.

My idea,
in sql have a table tickets
in the table have fields ticket_num name …

on the php
var $start_num $end_num $current_num $last_num
in the script have it check the table for the $last_num
then make $current_num = $last_num+1
if the $current_num > $end_num error out
if the $current_num < $start_num error out
in the paypal script just give it a hidden field of $current_num
and input the data back into the table for the next order

the only problem i see with this is efficiency and what if 2 orders happen at the same time? they will skip number yes?

is there a better way?

how many tix do you have?

if say 100 or fewer maybe you could list with tix number and just allow purchase, much like sku number
this will eliminate the ‘same time purchase’ issue for sure

just a thought

thanks

yea about 100 or so, looking at their setup for that i dont see how it would auto increment the sku/ticket number. as i have to use this ticket # to verify the ticket

these tickets are for a benefit dinner so i have to make sure that all tickets are accounted for as they are turned in by the intended person that purchased them.

why not do this

set up the pmt link and each time someone orders, assign them a tix number
keep track somehow
turn in extra tix at the end

why go through the trouble of it online
it really doesn’t matter what the ticket number is does it

except for $ reasons

why go through the trouble
not being sarcastic just a lot of work for a temp issue

in other words you can track and assign tix numbers in excel or something after purchase

the main reason is because we are a national non profit org and we will have people from all over attending. making it easier for them to purchase is the goal. and trying to make it easier to control/manage. as for the ticket num yes it matters as we have only a few tickets to supply so we need to track who gets which ticket not only for attendance but raffling as well.

Understood probably over my head now sorry

When registering an event

Register event data to an event table in the DB

events: id, title, description, start, end, etc

Generate x number of tickets (just choose a number in the register event form)

I could see this working with UUID, which will make it harder to guess than incrementing numbers.

tickets: id, event_id, user_id, code, reserved, purchased, refunded, etc

Then when a user adds tickets to the cart you reserve x number of tickets from the tickets table

SELECT * FROM tickets WHERE user_id IS NULL AND reserved IS NULL ORDER BY id DESC LIMIT 0 , 5 <-- number of tickets to reserve

Then reserve the ids you got with reserved = now(), if you get less than the reserved number you should show an error like “we don’t have that many tickets left”

Then either add a cron to remove reserved data from the DB, or just change the query above to check if reserved is NULL or more than x minutes ago (to invalidate reservations that didn’t result in an order)

I think something like this should work fine…

Sponsor our Newsletter | Privacy Policy | Terms of Service