I am implementing a referral system in which a user can come form a reference of a previously registered user of my system or can register manually without any reference. The problem I am facing is that if the user is not using a reference token to register then the referee of the user is that user itself. How can I save the data (foreign key) of the user before getting the primary key of that row (that comes from auto increment method)? For more clearance I am attaching this image.I am implementing a referral system in which a