I am making an audit for a form which takes into account the available fields.
I have the columns, session_id (the id of that current form created) ,fieldname, old value, new value. The old value is only populated if the user decides to change a value in the form and saves it.
So ideally when a user fills out a form first time and saves it, it should create new rows (3 rows in this example as there's only 3 fields) with the given details.
|-----------------------------------------|
| ID | Fieldname | Old Value | New Value |
|_________________________________________|
| 123 | Title | | Mr |
|_________________________________________|
| 123 | FirstName | | Bob |
|_________________________________________|
| 123 | LastName | | Smith |
|-----------------------------------------|
That audit is from one form with 3 fields. Is there a way to do this in one sql request? Populate the table with all the fieldnames available in the form.
An example of if I was to update a field.
|-----------------------------------------|
| ID | Fieldname | Old Value | New Value |
|_________________________________________|
| 123 | Title | | Mr |
|_________________________________________|
| 123 | FirstName | Bob | Tim |
|_________________________________________|
| 123 | LastName | | Smith |
|-----------------------------------------|