Trying to loop through an array for multiple database inserts

I am trying to pass an array to a server connect database insert, for some reason I am only getting the first record inserted (the repeat is not looping through the array)

The input array was created thus:

image

When I test my input I can see multiple entries into the array (before I changed the type to hidden). Any ideas as to why it is only inserting the first record in each array?

It appears that (maybe?) my index is being taken as a literal and not a numeric value…

image

I’ll try remedying that.

leave a static name in as name = "uname"
but then add dmx-bind:name="director_uname[{{$index}}][uname]"

do the same with an id. Have a static one and one using dmx-bind

1 Like

I am getting closer. I can see the indexed values in the developer panel

image

But I am still only getting the first value inserted into my table. It loops once and then errors.

image

I am using the array as the expression in my server action, but I don’t understand why it is only processing the first value…

Does the error have more detail when you run it through the XHR section of the inspect panel?

Not really.

image

Everything works fine when I am submitting a single array value, it fails when when the array has more than one value present.

that isn’t the XHR area in the element inspect its under network tab select XHR then refresh the page and they will pop up

Looks like I need to set debug flags for more details

image

I’m not certain how to do that.

I recreated the server action file (just in case there was something funky about it). You can see here it failed twice when I had multiple values in the director_uname array, but worked without error where I only submitted a single value in the array

As usual when you have errors with server actions …

Everything is described in this article!

1 Like

Thank you. That helps. It appears the issue is with my one of the fields I’m inserting.

  1. {code: “23000”,…}

    1. code: “23000”
    2. file: “/var/www/vhosts/wrec.coop/subdomains/bod/httpdocs/dmxConnectLib/lib/db/Connection.php”
    3. line: 140
    4. message: “SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘ee9a24ef87’ for key ‘travel’”

It is working now. The real issue is that I was using a “Now” as the seed to a random code I was saving, and it was processing too fast to change the value so it was breaking the “unique” parameter of the field in my database. Thanks everyone for the help…

1 Like