Have you coded to dynamically write a Form Update Query?

I’m looking to write the UPDATE RECORD query sent to the server based on which inputs the user has changed. For instance in a php mysql or Maria db project

Standard Wappler API UPDATE QUERY is something like this –

UPDATE story_data_ukd SET collection_id=’[value-1]’,story_ID=’[value-2]’,story_collector=’[value-3]’,datum=’[value-4]’,art_interview=’[value-5]’,form_interview=’[value-6]’,story=’[value-7]’,gefuehl_1=’[value-8]’,werte_1=’[value-9]’,personen_1=’[value-10]’,triangle_einfluss=’[value-11]’,slider_anteil=’[value-12]’,slider_einfluss=’[value-13]’,skala_zukunft=’[value-14]’,team=’[value-15]’,umfang_1=’[value-16]’,geschlecht=’[value-17]’,new_datum=’[value-18]’ WHERE collection_id = {{$_POST.collection_id}}

UPDATE and SET queries must return all of the existing data, too, whether changed or unchanged, when it is the form update user who will choose which inputs to affect or leave alone.
Even if the user decides only to change values in one input data field the Submit Change Query will have to pass along the retrieved (existing) unchanged values for all of these fields, too.

I would like to send an update query that only SETs the inputs actually changed by the user.

As in –

UPDATE story_data_ukd SET team=’[value-15] WHERE collection_id = {{$_POST.collection_id}}

The javascript related Wappler component on the Update Record form page determines which inputs were selected and modified and dynamically submits the update and set query required to update only changed inputs. Such as –

UPDATE story_data_ukd SET story_ID=’[value-2]’,form_interview=’[value-6]’ WHERE collection_id = {{$_POST.collection_id}}

Have any Wappler developers written their update form pages to refine their Update queries with the dynamic browser action components provided by Wappler?

Thank you for helpful replies!

I am not sure why you would want to do that.

The way that the update function normally works, it requires a value for each of the fields listed in the database updater, or they will revert to the default value. This could be a zero.

To achieve what you want, you would need 18 database updaters containing one field each plus a condition pointing to the record. Each of these database updaters would need to be controlled using if-then-else statements.

Personally, I do not see the point in doing that. However, I stand to be corrected.

UPDATE query is not like the INSERT query.

UPDATE the target row by its key and use SET just once to overwrite just one specified field.
Or, add more fields separating the field name and its new value with a comma between each new value in another field.

Here all I need is one field with its new value because the query to mysql addresses the cool parameters of using UPDATE and its properties.

Now I just update the same record with another field and add some new text. I only need UPDATE once and SET once. Which is why I want to send the shortest necessary query to update my record.

I believe this can be done with a combination of API custom query and form filtering via javascript in DOM.

And the UPDATE to add the new text only needed THIS

UPDATE story_data_ukd SET story = “my new text to add to existing text area values” WHERE collection_id = 30

In my update form I could have written anything I wanted in the text area and the query would have contained all the existing text as well.

But the query only needed this to work, not a null or empty value for all other “empty” fields in the record.

UPDATE story_data_ukd SET story = “my new text to add to existing text area plus all my original paragraphs” WHERE collection_id = 30

I just found one way in a php & mysql application to Dynamically write the Update Query in an UPDATE FORM

I know node and js scripts also exist to do the same.
Act to create exactly the update query needed.