<p>I created a matrix with 1 type, 3 fields for user profile. I use front-end to upload file to documentUpload field. But I got PHP warning: <code>array_merge(): Argument #1 is not an array message</code>. I Google it and see <a href="https://github.com/am-impact/amforms/issues/29" rel="nofollow noreferrer">this issue</a>. I did try adding</p>

<pre><code>if (empty($value)) {
    $value = array();
}
</code></pre>

<p>But I still got the same issue. Not sure how I could resolve the issue. I see my file is uploaded to AWS S3. Looks it has issue to save it in Craft. Does anyone know how to solve it? Thanks</p>

<p>Here is my code to upload file:</p>

<pre><code>&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
 {{ getCsrfInput() }}
&lt;input type="hidden" name="action" value="users/saveUser"&gt;
&lt;input type="hidden" name="fields[petRecords][new{{ next }}][type]" value="records"&gt;
&lt;input type="hidden" name="fields[petRecords][new{{ next }}][enabled]" value="1"&gt;
&lt;input type="file" name="fields[petRecords][new{{ next }}][fields][documentUpload]" /&gt;
&lt;input type="text" name="fields[petRecords][new{{ next }}][fields][description]" /&gt;
&lt;input type="text" name="fields[petRecords][new{{ next }}][fields][petIdNumber]" /&gt;
&lt;input class="btn btn-primary btn-block btn-social" type="submit" value="continue"&gt;
&lt;/form&gt;
</code></pre>

<p><a href="https://i.sstatic.net/SACb5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/SACb5.png" alt="configuration"></a>
My Craft CMS version is 2.6.2980
<a href="https://i.sstatic.net/c7QwI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/c7QwI.png" alt="Error message"></a></p>

CC BY-SA 3.0
2017-05-26T17:09:45.023Z
Have you tried passing your file field as an array, adding `[]` at the end?`fields[petRecords][new{{ next }}][fields][documentUpload][]`
Matt Stein
CC BY-SA 3.0
2017-05-26T17:24:54.373Z
You're linking to an [amforms plugin](https://github.com/am-impact/amforms/issues/29) issue. Is this an amforms form?  Doesn't look like it because it's calling `users/saveUser`.
Brad Bell
CC BY-SA 3.0
2017-05-26T18:28:05.733Z
@matt-stein, Adding `[]` looks that issue is gone. but when I enter another file, I got error. After I refresh my page and add the file again, it allows me to add a file. Looks the tagetID is not loaded on the first time.
Angela Chan
CC BY-SA 3.0
2017-05-26T18:28:12.793Z
`CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'targetId' cannot be null. The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, NULL, :row0_col4, :row0_col5, :row0_col6, :row0_col7). Bound with :row0_col0='98', :row0_col1='522', :row0_col4=1, :row0_col5='2017-05-26 18:22:39', :row0_col6='2017-05-26 18:22:39', :row0_col7='75187a4d-f2fc-4389-9c35-f42b9ba1f17c'`
Angela Chan
CC BY-SA 3.0
2017-05-26T18:28:57.087Z
@BradBell, I'm not using amforms, looks I am on the wrong direction.
Angela Chan
CC BY-SA 3.0
2017-05-26T18:31:24.873Z
If I'm following you, @AngelaChan, you would also need to add `multiple` to your field if you're attempting to add more than one file to it. Example [here in P&T's docs](https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms).
Matt Stein
CC BY-SA 3.0
2017-05-26T23:41:14.207Z
I see your new question [here](https://craftcms.stackexchange.com/questions/20603/cdbexception-error-when-upload-files-to-matrix-field-on-front-end), @AngelaChan. Can you add the `[]` fix as an answer to this one in case other people might have the same issue?
Brad Bell
<matrix><php><upload>
Frontend upload asset to Matrix
# Frontend upload asset to Matrix

(Asked by: username_0 on 2017-05-26)

I created a matrix with 1 type, 3 fields for user profile. I use front-end to upload file to documentUpload field. But I got PHP warning: array_merge(): Argument #1 is not an array message. I Google it and see this issue. I did try adding
if (empty($value)) {
    $value = array();
}

But I still got the same issue. Not sure how I could resolve the issue. I see my file is uploaded to AWS S3. Looks it has issue to save it in Craft. Does anyone know how to solve it? Thanks
Here is my code to upload file:

 {{ getCsrfInput() }}










My Craft CMS version is 2.6.2980

**Tags:** matrix, php, upload

> **Comments:**
> **username_1**: Have you tried passing your file field as an array, adding `[]` at the end?`fields[petRecords][new{{ next }}][fields][documentUpload][]`  
> **username_2**: You're linking to an [amforms plugin](https://github.com/am-impact/amforms/issues/29) issue. Is this an amforms form?  Doesn't look like it because it's calling `users/saveUser`.  
> **username_0**: @matt-stein, Adding `[]` looks that issue is gone. but when I enter another file, I got error. After I refresh my page and add the file again, it allows me to add a file. Looks the tagetID is not loaded on the first time.  
> **username_0**: `CDbCommand failed to execute the SQL statement: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'targetId' cannot be null. The SQL statement executed was: INSERT INTO `craft_relations` (`fieldId`, `sourceId`, `sourceLocale`, `targetId`, `sortOrder`, `dateCreated`, `dateUpdated`, `uid`) VALUES (:row0_col0, :row0_col1, NULL, NULL, :row0_col4, :row0_col5, :row0_col6, :row0_col7). Bound with :row0_col0='98', :row0_col1='522', :row0_col4=1, :row0_col5='2017-05-26 18:22:39', :row0_col6='2017-05-26 18:22:39', :row0_col7='75187a4d-f2fc-4389-9c35-f42b9ba1f17c'`  
> **username_0**: @BradBell, I'm not using amforms, looks I am on the wrong direction.  
> **username_1**: If I'm following you, @AngelaChan, you would also need to add `multiple` to your field if you're attempting to add more than one file to it. Example [here in P&T's docs](https://craftcms.com/docs/assets-fields#uploading-files-from-front-end-entry-forms).  
> **username_2**: I see your new question [here](https://craftcms.stackexchange.com/questions/20603/cdbexception-error-when-upload-files-to-matrix-field-on-front-end), @AngelaChan. Can you add the `[]` fix as an answer to this one in case other people might have the same issue?  

---

## 0 answers

