Forums

DB Save - Update or Insert

sortby 05 Oct, 2015
Hello,
I'm saving form data of user's test on the DB.
fields are 3 : ID - User_id - result

Whereas users can make multiple time the test, my goal is to update only the record (with new (latest) user result) instead of create a new record. ( so my goal is to have only one record for each user with latest result)

Is there a chance to do it, if yes ca you point me to some implementation?
Many thanks🙂
GreyHead 05 Oct, 2015
Hi sortby,

There are two ways to do this.

A. In the On Load event you look up to see if there is an existing record. You do this if you want to show the existing record for editing. Please see this FAQ

B. In the On Submit event set the DB Save action to update the record with the same User ID. I guess that some users will have a record and others will not have one yet. To make sure that it is saved you need to check for an existing record in the same way as in the FAQ above. If one is found, add the record ID to the $form->data[''] array, if not leave it un-set so that a new record is created.

Bob
This topic is locked and no more replies can be posted.