Forums

Edit Creates Duplicate Data Entry

hopemanjohn 24 Feb, 2013
Hi Bob,

I have searched everywhere for this answer and I am sure that it has been asked many times before but I can’t find the solution.

I have a form which saves to a database correctly. It has a key field name called “code”.

I can recall the data into a copy of the first form to edit by using the key field “code”.

All works well, however, when I click save data from the edit form it does not alter the original data but creates another form but with the same key field called code.

If a user wants to view this data in a view form using the key code what they get is the original un-edited entry.

Help!!
GreyHead 24 Feb, 2013
Hi hopemanjohn,

To use the ChronoForms DB Save to update a record your table needs to have a numeric Primary Key defined and the form data need to include the primary key value e.g. $form->data['id'] = 99

The Primary Key doesn't need to be the same as the 'code' key field that you use to retrieve the record.

Bob
hopemanjohn 25 Feb, 2013
Hi Bob,

Your FAQ on how to edit a record stops at the loading of the record and says nothing about how it should be saved without creating a duplicate.

I’m sorry but your reply has lost me. Your for example: $form->data[‘id’]=99 is meaningless to a poor sod like me without it being explained. I cannot see anywhere, within the DB Save to define any numeric Primary Key. It just asks you to specify the DB form to be saved into.

I know that when a record is created it is given both a “cf_id” and a “cf_uid” which are unique to the record. I assume that the primary key has to be one of the above, but how and where can you specify an unknown id?

John
GreyHead 25 Feb, 2013
Hi John,

If your table was created with ChronoForms and has a 'cf_id' column then almost certainly that is the Primary Key. A quick check in PHPMyAdmin will confirm that. In that case if you add a hidden input to your form with the name cf_id then ChronoForms will add the value from the DB Record Loader and that record should be updated.

Please see this FAQ for more about the $form->data array.

You are right about the 'edit' FAQ, I've made a note to extend that when I have some time.

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