DBSave: insert when new, else update

jpurlings 18 Nov, 2016
Hi,

I want a form to add a new record to a database if the user doesn't have a record yet. Else I want to update existing record. With help of Bob I got the update to work. But now I can't figure out how to distinguish between saving a new user (via insert) and updating an existing user...?

Greetings.
GreyHead 18 Nov, 2016
Hi jpurlings,

If the form data includes the value of an existing Primary key value from the table e.g. $form->data['cf_id'] = 999 then the record will be updated, if there is no value set, or it doesn't match an existing record a new one is created.

Note: if the primary key column is named id then there can be problems if the page URL also included an article id!

Bob
jpurlings 18 Nov, 2016
Bob,

Thank you. I think that I did that, but I must be doing something wrong. Credentials of the site are still the same as I sent you, could you please have a look at it?

Thank you.
GreyHead 18 Nov, 2016
Hi jpurlings,

I still can't access the site - I get this

This site can’t be reached

www.bizzaccelerator.biz took too long to respond.
Search Google for biz accelerator administrator
ERR_CONNECTION_TIMED_OUT

Looks like it is going to a BIT BV IP address and then nothing.

Bob
jpurlings 20 Nov, 2016
Bob,

That strange. I tried the site on several pc's and laptops, it works everywhere. The error warning could also be caused by your pc, as this site suggests: http://www.incrediblelab.com/connection-timed-out-error-fixed/.

Hopefully you can enter the site to see what I am doing wrong.

Greetings.
GreyHead 20 Nov, 2016
Hi jpurlings,

Right now I can see the site - but it's close to midnight - I'll check again in the morning.

Bob
jpurlings 21 Nov, 2016
Okay,

Great! Looking forward to your solution.

Greetings.
GreyHead 21 Nov, 2016
Answer
Hi jpurlings,

I think that is working now. There were various fixes needed - some of them may be from previous debugging attempts.

The main one was that you had a list of fields in the DB Read action that didn't include the cf_id primary key column. So that data wasn't being loaded and wasn't available on save.

There was also some code in the Designer tab that could have been used to get the cf_id value after a DB Save - but that didn't work after a DB Read.

Once the cf_id value is being correctly set in the hidden input the custom code in the DB Save conditions box is no longer needed.

I have also removed the Model ID settings from the DB Read and the DB Save as they are not used in the input element named and so the data would not save correctly.

Bob
jpurlings 21 Nov, 2016
Bob,

Great, it works now. I understand what you did. Thank you for the corrections and your explanation!

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