500 Internal Server Error when updating subtable / form repeat

Hey guys,

Wappler 5.8.2
Win 10
php 7.4.33
MySQL

I used a form repeat to insert values to the Main Table and its subtable (following this @Teodor’s tutorial: Using App Connect Form Repeater with Update Record Forms

Of course I also used the known upsert method by checking the main table’s id and proceed with a database update action if id is submitted otherwise a database insert action.


My Insert action (id not submitted) works fine.
But when I try to update a main/subtable record, when I submit my form I get this error:

{
    "code": 0,
    "file": "C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\dbupdater.php",
    "line": 288,
    "message": "Undefined property: stdClass::$returning",
    "trace": "#0 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\dbupdater.php(288): exception_error_handler(8, 'Undefined prope...', 'C:\\\\xampp\\\\htdocs...', 288, Array)\n#1 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(204): modules\\dbupdater->update(Object(stdClass), 'updateVariation...', Array)\n#2 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(176): lib\\App->execSteps(Object(stdClass))\n#3 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(144): lib\\App->execSteps(Array)\n#4 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\core.php(100): lib\\App->exec(Object(stdClass), true)\n#5 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(204): modules\\core->condition(Object(stdClass), '', NULL)\n#6 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(144): lib\\App->execSteps(Object(stdClass))\n#7 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(133): lib\\App->exec(Object(stdClass), false)\n#8 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(111): lib\\App->exec(Object(stdClass))\n#9 C:\\xampp\\htdocs\\datastore_test\\dmxConnect\\api\\variations\\variation_add.php(8): lib\\App->define(Object(stdClass))\n#10 {main}"
}

After a couple of test I realized that the problem is only when updating the subtable entries.

**There is no 500 error in the following 2 cases:

  • I delete the formrepeat field (array) from the update database step and just update the main’s table data
  • I remove all the subtable records in my form and then click submit. It submits normally without an error 500 (but not updating / deleting the subtable records that I deleted in my form)

While trying to figure this out I noticed that there are 4 updates in my wappler’s project:

  • App
  • Text
  • Date
  • Arraylist

App and Arraylist is these 2 that I have updated with new files that patrick has gave me in order to solve Arraylist errors a few days ago. Sort array bug (SC)

So, I clicked the update button and after that I tried to run the same server action that had problem when patrick solved it and I get again the same error:

{
    "code": 0,
    "file": "C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\arraylist.php",
    "line": 15,
    "message": "Creation of dynamic property lib\\App::$arrays is deprecated",
    "trace": "#0 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\arraylist.php(15): exception_error_handler(8192, 'Creation of dyn...', 'C:\\\\xampp\\\\htdocs...', 15)\n#1 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(204): modules\\arraylist->create(Object(stdClass), 'list', Array)\n#2 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(176): lib\\App->execSteps(Object(stdClass))\n#3 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(144): lib\\App->execSteps(Array)\n#4 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(133): lib\\App->exec(Object(stdClass), false)\n#5 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(111): lib\\App->exec(Object(stdClass))\n#6 C:\\xampp\\htdocs\\datastore_test\\dmxConnect\\api\\users\\registration\\usr_login_copy.php(7): lib\\App->define(Object(stdClass))\n#7 {main}"
}

Your help would be much appreciated…

Thanks in advance

Did the updated App.php for the arrays not work? The one posted at

The first error looks like a property is not set by Wappler, can you post the generated json of the server connect action.

I am Sorry… My mistake, I pasted in wrong project the app.
I fixed it bey pasting it in the correct one.
So, Arraylist works FINE.

Now, for the dbupdater 500 error, you mean the generated variation_add.php? (I use php)

<?php
require('../../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
  "meta": {
    "options": {
      "linkedFile": "/admin.php",
      "linkedForm": "frm_UpsertVariation"
    },
    "$_POST": [
      {
        "type": "text",
        "fieldName": "var_id",
        "options": {
          "rules": {
            "core:number": {}
          }
        },
        "name": "var_id"
      },
      {
        "type": "text",
        "fieldName": "var_name",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            }
          }
        },
        "name": "var_name"
      },
      {
        "type": "array",
        "name": "formRepeatVariationValues",
        "sub": [
          {
            "type": "text",
            "fieldName": "formRepeatVariationValues[{{$index}}][var_val_name]",
            "options": {
              "rules": {}
            },
            "name": "var_val_name"
          },
          {
            "type": "text",
            "fieldName": "formRepeatVariationValues[{{$index}}][var_val_extraprice]",
            "options": {
              "rules": {
                "core:number": {},
                "core:min": {
                  "param": 1
                }
              }
            },
            "name": "var_val_extraprice"
          }
        ]
      },
      {
        "type": "text",
        "fieldName": "var_cat_id",
        "options": {
          "rules": {
            "core:required": {
              "param": ""
            }
          }
        },
        "name": "var_cat_id"
      }
    ]
  },
  "exec": {
    "steps": {
      "name": "",
      "module": "core",
      "action": "condition",
      "options": {
        "if": "{{$_POST.var_id}}",
        "then": {
          "steps": [
            {
              "name": "updateVariation",
              "module": "dbupdater",
              "action": "update",
              "options": {
                "connection": "conn_dstore",
                "sql": {
                  "type": "update",
                  "values": [
                    {
                      "table": "variations",
                      "column": "var_name",
                      "type": "text",
                      "value": "{{$_POST.var_name}}"
                    },
                    {
                      "table": "variations",
                      "column": "var_cat_id",
                      "type": "number",
                      "value": "{{$_POST.var_cat_id.toNumber()}}"
                    }
                  ],
                  "table": "variations",
                  "wheres": {
                    "condition": "AND",
                    "rules": [
                      {
                        "id": "var_id",
                        "type": "double",
                        "operator": "equal",
                        "value": "{{$_POST.var_id}}",
                        "data": {
                          "column": "var_id"
                        },
                        "operation": "="
                      }
                    ]
                  },
                  "returning": "var_id",
                  "query": "update `variations` set `var_name` = ?, `var_cat_id` = ? where `var_id` = ?",
                  "params": [
                    {
                      "name": ":P1",
                      "type": "expression",
                      "value": "{{$_POST.var_name}}",
                      "test": ""
                    },
                    {
                      "name": ":P2",
                      "type": "expression",
                      "value": "{{$_POST.var_cat_id.toNumber()}}",
                      "test": ""
                    },
                    {
                      "operator": "equal",
                      "type": "expression",
                      "name": ":P3",
                      "value": "{{$_POST.var_id}}",
                      "test": ""
                    }
                  ]
                }
              },
              "meta": [
                {
                  "name": "affected",
                  "type": "number"
                }
              ],
              "output": false,
              "disabled": true
            },
            {
              "name": "updateVariation_copy",
              "module": "dbupdater",
              "action": "update",
              "options": {
                "connection": "conn_dstore",
                "sql": {
                  "type": "update",
                  "values": [
                    {
                      "table": "variations",
                      "column": "var_name",
                      "type": "text",
                      "value": "{{$_POST.var_name}}"
                    },
                    {
                      "table": "variations",
                      "column": "var_cat_id",
                      "type": "number",
                      "value": "{{$_POST.var_cat_id}}"
                    }
                  ],
                  "table": "variations",
                  "wheres": {
                    "condition": "AND",
                    "rules": [
                      {
                        "id": "var_id",
                        "type": "double",
                        "operator": "equal",
                        "value": "{{$_POST.var_id}}",
                        "data": {
                          "column": "var_id"
                        },
                        "operation": "="
                      }
                    ]
                  },
                  "sub": {
                    "var_values": {
                      "type": "insert",
                      "table": "variation_var_values",
                      "key": "variation_id",
                      "values": [
                        {
                          "table": "variation_var_values",
                          "column": "var_val_name",
                          "type": "text"
                        },
                        {
                          "table": "variation_var_values",
                          "column": "var_val_extraprice",
                          "type": "number"
                        }
                      ],
                      "value": "{{$_POST.formRepeatVariationValues}}"
                    }
                  },
                  "returning": "var_id",
                  "query": "update `variations` set `var_name` = ?, `var_cat_id` = ? where `var_id` = ?",
                  "params": [
                    {
                      "name": ":P1",
                      "type": "expression",
                      "value": "{{$_POST.var_name}}",
                      "test": ""
                    },
                    {
                      "name": ":P2",
                      "type": "expression",
                      "value": "{{$_POST.var_cat_id}}",
                      "test": ""
                    },
                    {
                      "operator": "equal",
                      "type": "expression",
                      "name": ":P3",
                      "value": "{{$_POST.var_id}}",
                      "test": ""
                    }
                  ]
                }
              },
              "meta": [
                {
                  "name": "affected",
                  "type": "number"
                }
              ],
              "output": false
            }
          ]
        },
        "else": {
          "steps": {
            "name": "insertVariation",
            "module": "dbupdater",
            "action": "insert",
            "options": {
              "connection": "conn_dstore",
              "sql": {
                "type": "insert",
                "values": [
                  {
                    "table": "variations",
                    "column": "var_name",
                    "type": "text",
                    "value": "{{$_POST.var_name}}"
                  },
                  {
                    "table": "variations",
                    "column": "var_cat_id",
                    "type": "number",
                    "value": "{{$_POST.var_cat_id}}"
                  }
                ],
                "table": "variations",
                "returning": "var_id",
                "query": "insert into `variations` (`var_cat_id`, `var_name`) values (?, ?)",
                "params": [
                  {
                    "name": ":P1",
                    "type": "expression",
                    "value": "{{$_POST.var_name}}",
                    "test": ""
                  },
                  {
                    "name": ":P2",
                    "type": "expression",
                    "value": "{{$_POST.var_cat_id}}",
                    "test": ""
                  }
                ],
                "sub": {
                  "var_values": {
                    "type": "insert",
                    "table": "variation_var_values",
                    "key": "variation_id",
                    "values": [
                      {
                        "table": "variation_var_values",
                        "column": "var_val_name",
                        "type": "text"
                      },
                      {
                        "table": "variation_var_values",
                        "column": "var_val_extraprice",
                        "type": "number"
                      }
                    ],
                    "value": "{{$_POST.formRepeatVariationValues}}"
                  }
                }
              }
            },
            "meta": [
              {
                "name": "identity",
                "type": "text"
              },
              {
                "name": "affected",
                "type": "number"
              }
            ],
            "output": false
          }
        }
      },
      "outputType": "boolean"
    }
  }
}
JSON
);
?>

Thank you for posting the json, I see that the returning prop is indeed missing from the sub query. Will investigate this further.

1 Like

Still have to fix this, but I found a workaround for now. When you double click the column with the sub table it opens a dialog with the insert query for that sub table, just click ok there and it will save the correct data.

1 Like

I’m sorry but don’t understand…
Column you mean in database manager?

In the insert/update record dialog.

I Love you guys! Now it updates properly! No errors, clean and clear

I don’t know why you say that… but you know…

Thanks a lot brothers

We found the issue and it will be fixed in the next beta release. There was a property not being set when you just add a sub table as column without opening the dialog for the sub table query.

1 Like

Hello @Teodor and @Patrick,

In addition to our conversation (and your temporary solution waiting for the next update to solve it) about Updating Main/subtable records, I just wanted to let you know that I have already managed to submit and Insert to my database Successfully the results of my DataStore with Array fields demo here:

As you understand I’m dealing with 2 level of subTables here:
– Main (orders)
—> Subtable (order_products)
------> Subtable/Subtable (order_product_variations)
My Schema:

Now I faced again a 500 Interval error, when I’m trying to update an order…
(of course by using the same workaround as the Database Insert)

I attach my Server Action Screenshots:

I don’t have this error if I remove the 2nd level Subtable(formRepeatVariations) from the update step inside the repeat, but then no products are updated also…

So, the error i get is:

{
    "code": "42000",
    "file": "C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\dbupdater.php",
    "line": 294,
    "message": "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1",
    "trace": "#0 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\dbupdater.php(294): PDO->prepare()\n#1 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(206): modules\\dbupdater->update()\n#2 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(178): lib\\App->execSteps()\n#3 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(146): lib\\App->execSteps()\n#4 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\modules\\core.php(69): lib\\App->exec()\n#5 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(206): modules\\core->repeat()\n#6 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(178): lib\\App->execSteps()\n#7 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(146): lib\\App->execSteps()\n#8 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(135): lib\\App->exec()\n#9 C:\\xampp\\htdocs\\datastore_test\\dmxConnectLib\\lib\\App.php(113): lib\\App->exec()\n#10 C:\\xampp\\htdocs\\datastore_test\\dmxConnect\\api\\orders\\order_update.php(7): lib\\App->define()\n#11 {main}"
}

And my Payload:

ord_id: 34
ord_usr_id: 1
ord_date: 2023-08-07
formRepeatProducts[0][ord_product_id]: 3
formRepeatProducts[0][ord_prd_quantity]: 3
formRepeatProducts[0][ord_prd_price]: 245.00
formRepeatProducts[0][formRepeatVariations][0][ord_prd_var_Var_id]: 4
formRepeatProducts[0][formRepeatVariations][0][ord_prd_var_Val_id]: 19
formRepeatProducts[0][formRepeatVariations][0][ord_prd_var_Val_exprice]: 10.00
formRepeatProducts[1][ord_product_id]: 7
formRepeatProducts[1][ord_prd_quantity]: 2
formRepeatProducts[1][ord_prd_price]: 32.00
formRepeatProducts[1][formRepeatVariations][0][ord_prd_var_Var_id]: 3
formRepeatProducts[1][formRepeatVariations][0][ord_prd_var_Val_id]: 14
formRepeatProducts[1][formRepeatVariations][0][ord_prd_var_Val_exprice]: 1.00
formRepeatProducts[1][formRepeatVariations][1][ord_prd_var_Var_id]: 5
formRepeatProducts[1][formRepeatVariations][1][ord_prd_var_Val_id]: 48
formRepeatProducts[1][formRepeatVariations][1][ord_prd_var_Val_exprice]: 5.00
formRepeatProducts[2][ord_product_id]: 6
formRepeatProducts[2][ord_prd_quantity]: 2
formRepeatProducts[2][ord_prd_price]: 368.00
formRepeatProducts[2][formRepeatVariations][0][ord_prd_var_Var_id]: 2
formRepeatProducts[2][formRepeatVariations][0][ord_prd_var_Val_id]: 11
formRepeatProducts[2][formRepeatVariations][0][ord_prd_var_Val_exprice]: 30.00

  • 1) I remind you that the same workaround is working perfect for the Database Insert.

  • 2) Of course I did the trick to open every subtable and click OK but no luck…

If you have some time to take a look at it would be very kind of you.
If you need any other information please ring my bell.

Thanks in advance

This has been fixed in the latest beta updates.

1 Like