how to make the "paid plans" application, from wix auto connect to a database using the 'reference' field

I’m trying to figure out how to make the database automatically put a reference to the plan that a user signed.

let’s say the plan is called ‘basic’, when a user acquires this plan I need him


I don’t know where to start, I need an insert() code??

how can i start?