# Combining "form" and "dropdown" payload data and building a mysql query

**URL:** <https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377>\
**Category:** General\
**Created:** [20 July 2020 07:51 UTC](https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377 "2020-07-20T07:51:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zazas321](https://avatars.discourse-cdn.com/v4/letter/z/59ef9b/32.png) [@zazas321](https://discourse.nodered.org/u/zazas321)\
**Post date:** [20 July 2020 07:51 UTC](https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377/1 "2020-07-20T07:51:06Z")

</div>

Hello. I am trying to build an MYSQL query from user input "form" and "dropdown" nodes.

 ![2020-07-20-105649_1920x1080_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9cc0e87b36c0dcc1d0e7989ed0a0ed37231ae0c.png)

 ![2020-07-20-104339_1920x1080_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b359fbba9a3caf547d834129237c7f0f4d3cb61d.png)

I am using "change" nodes and "join" node to build an array out of 3 inputs that the user needs to give : Device,Item,Serial. Then I use function node to build a query that I will be sending to mysql, however, the function node does not recognise the payload input that I give:

```auto
device = msg.payload[0]
item = msg.payload[1]
serial = msg.payload[2]

msg.topic="INSERT INTO pack_to_light (Device,Item,Serial) VALUES ('${device}','${item}',${serial})";

return msg;

```

Is this not correct way to assign payload array to a function?

The output that I get:

```auto

{"payload":"Error: ER_PARSE_ERROR: 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 '{serial})' at line 1"

```

For some reason, the problem happens when I try to insert data as integer. It gives me an error even though I have declared "serial" as integer on my database

However, when i change the Serial variable to VARCHAR instead of integer and add brackets, the sql querry works, but it injects the following:

 ![2020-07-20-110146_1920x1080_scrot](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2e3914708dcc3e07463c58069fc39da76d647ee.png)  
instead of actual payload data, it have injected {device}, {item}, ${serial}

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [20 July 2020 08:28 UTC](https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377/2 "2020-07-20T08:28:35Z")

</div>

To use variables in a string, change the double quotes to backticks.

ie.

```auto
msg.topic="INSERT INTO pack_to_light (Device,Item,Serial) VALUES ('${device}','${item}',${serial})";

```

should become:

```auto
msg.topic=`INSERT INTO pack_to_light (Device,Item,Serial) VALUES ('${device}','${item}',${serial})`;

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 July 2020 08:38 UTC](https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377/3 "2020-07-20T08:38:42Z")

</div>

Please don't open a second thread about the same topic: [How to pass payload data from user "form" to function](https://discourse.nodered.org/t/how-to-pass-payload-data-from-user-form-to-function/30106/16) as it wastes peoples time.

I am closing this thread

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 July 2020 08:38 UTC](https://discourse.nodered.org/t/combining-form-and-dropdown-payload-data-and-building-a-mysql-query/30377/4 "2020-07-20T08:38:47Z")

</div>


