Error: Array to string conversion

I followed the tutorial “Inserting Data in Main and Sub Table using App Connect Form Repeat” (https://community.wappler.io/t/inserting-data-in-main-and-sub-table-using-app-connect- form-repeat/41648) and when saving the data, Wappler returns an error in the console: Array to string conversion.
Did I miss some detail?

TABLE STRUCTURE:

Main Table whats_included:

whats_id - int (auto increment and unsigned)
whats_pct_id - int
whats_title - varchar
whats_create_at - datetime
whats_update_at - datetime
whats_status - int

Whats_included_contents SubTable:

id - int (auto increment and unsigned)
content - varchar
whats_included_id - int

This is the form code:

    <form id="form1" is="dmx-serverconnect-form" method="post" action="/dmxConnect/api/Pacotes/eng/whats_insert.php">

    <div class="row">

    <legend class="col-form-label">Whats título</legend>

    <div class="col">

    <div class="form-group mb-3">

    <label for="input1" class="form-label">Título</label>

    <input type="text" class="form-control" id="input1" name="whats_title" aria-describedby="input1_help" placeholder="Digite o título" required="" data-msg-required="Campo obrigatório.">

    <small id="input1_help" class="form-text text-muted">Your input is very valuable.</small>

    </div>

    </div>

    <div class="col">

    <div class="form-group mb-3">

    <label for="inp_whats_pct_id" class="form-label">Pacote ID</label>

    <input type="number" class="form-control" id="in_whats_pct_id" name="whats_pct_id" aria-describedby="in_whats_pct_id_help" placeholder="ID do pacote" required="">

    <small id="in_whats_pct_id_help1" class="form-text text-muted">Your input is very valuable.</small>

    </div>

    </div>

    </div>

    <div class="row">

    <legend class="col-form-label">Conteúdos:</legend>

    <div is="dmx-form-repeat" id="formRepeat1" dmx-bind:items="1">

    <div class="row">

    <div class="col">

    <input id="content_id" name="conteudo" type="text" class="form-control" placeholder="Digite o conteúdo">

    </div>

    <div class="col-4">

    <button id="btn1" class="btn btn-danger" dmx-on:click="formRepeat1.remove()">Delete</button>

     </div>

     </div>

     </div>

    </div>

    <button id="btn2" class="btn btn-info" dmx-on:click="formRepeat1.add()">Novo conteúdo</button>

    <button id="btn3" class="btn btn-success" type="submit">Salvar dados</button>

    </form>

This is the code in the console.
{code: 0, file: “C:\laragon\www\onneviagens_trilingue\dmxConnectLib\lib\db\Connection.php”, line: 141,…}
code
:
0
filet
:
“C:\laragon\www\onneviagens_trilingue\dmxConnectLib\lib\db\Connection.php”
line
:
141
message
:
“Array to string conversion”
trace
:
#0 [internal function]: exception_error_handler(2, ‘Array to string…’, ‘C:\\laragon\\www\\…’, 141)\n#1 C :\laragon\www\onneviagens_trilingue\dmxConnectLib\lib\db\Connection.php(141): PDOStatement->bindParam(1, Array, 2)\n#2 C:\laragon\ www\onneviagens_trilingue\dmxConnectLib\modules\dbupdater.php(164): lib\db\Connection->execute(‘INSERT INTO `wh…’, Array, false, ‘whats_included_…’ )\n#3 C:\laragon\www\onneviagens_trilingue\dmxConnectLib\lib\App.php(204): modules\dbupdater->insert(Object(stdClass), ‘insert’, Array) \n#4 C:\laragon\www\onneviagens_trilingue\dmxConnectLib\lib\App.php(144): lib\App->execSteps(Object(stdClass))\n#5 C:\ \laragon\www\onneviagens_trilingue\dmxConnectLib\lib\App.php(133): lib\App->exec(Object(stdClass), false)\n#6 C:\laragon\www \onneviagens_trilingue\dmxConnectLib\lib\App.php(111): lib\App->exec(Object(stdClass))\n#7 C:\laragon\www\onneviagens_trilingue\dmxConnect\ \api\Packages\eng\whats_insert.php(8): lib\App->define(Object(stdClass))\n#8 {main}”

What version of Wappler are you using?
Have you updated all the files wich contain the fixes from previous bugs?
It’s ok the field named conteudo as you have a field named content?

Hello.
I tried in version 5.8.2 in Beta version 6.0 and it gives the same error.

Can you post some screenshots of the server side steps?

As explained in the docs about form repeat,

NOTE that the name of the input must be the same as the database table field name. In this case - name

so double check if your input names inside the form repeat are the same as the table field names.

Try {{$_POST.formRepeat1.conteudo}}

The expression for the subtable should be as it is now.
It’s the names of the inputs inside the form repeat that must match the subtable field names.

Hello.
Yes, the fields in the form are named the same as the fields in the table.
I’m going to delete and recreate the Main Table and subtable again.

I did it again and got the error again.
But I noticed that, when creating the subtable by Wappler, in the Waapler structure a field that is in the DB does not appear. The field is called whats_included_id. I believe that this field is what makes the connection between the two tables. But it does not appear in the structure of the subtable and it appears in the Insert Option as shown in the images.

I already deleted this field from Insert Option to test but it gives the same error. If this field has to stay, what bind do I have to do with it?

I compared the two Insert Option images and there is a difference.
In the tutorial there is no reference field (main table id) and in my image there are two fields: content and whats_included_id. The latter is automatically created by Wappler when I create the subtable.

I see your action $_POST parameters…

The formRepeatVariationRules should be an array type

I recorded a step-by-step video of how I’m doing it

Notice that when I edit the subtable in the query Builder, the data type is different from the tutorial. Contents is not as a subtable but as Text and the whats_included_id field of the subtable comes.
I don’t know what’s wrong. The version of Wappler that the tutorial was created on is different.

You insert the main table fields ok. But then you click the plus sign to add the subtable (formrepeat)

Ahhhhhh. Perfect.
Now it worked.
Thank you very much for your attention.

1 Like

Hi @famousmag
Inserting new records I manage perfectly.
I created another page just to update the data. This page loads the data according to the URL ID. It loads the records without problems but when I click on the UPDATE button, the system returns an error that I had not seen before.
Below is the console log screen.

Yes I have the same problem… I suppose you use wappler 5.8.2 , php, MySql?

It is reported here and @patrick is investigating it…

Hello.
Thank you very much for your attention. I checked the Post you referenced and let’s wait then because @patrick is still investigating.

1 Like