I want to implement a new system for referal/promotions. my new system where when a user register a specific source is assig to him. A source can be anything from referal (clients domain) and a promotion code (eg: 50% off). This source also have a date (y-m-d). Each source id is unique and multiple users can have the same source id
For example:
source id : 1 = www.domain1.com / 2011-11-20 / (empty referal code)
source id : 2 = www.domain1.com / 2011-11-20 / referalcode1
source id : 3 = www.domain2.com / 2011-11-20 / referalcode1
source id : 4 = www.domain2.com / 2011-11-20 / referalcode2
The referal code can be mixed from client1 to client 2
How can i make sure when someone register (its free registration and we have over 1000 per hours now) we dont have duplicate records and risk the mysql to generate errors?
From mysql page:
If the record does not exists, it will insert it and the last ID will be returned.
Now, if there’s not record returned, you can do your select. This means a record already exists, so simply use it.
Example:
At this point you will have
$idassigned and you are sure there’s no duplicate/mysql errors.Note: if a domain belongs to one client, use the client id instead of using the domain. This way you will use INT as index which is faster than VARCHAR. Same idea for referral code.