# Form data to database

**URL:** <https://discourse.nodered.org/t/form-data-to-database/11100>\
**Category:** Dashboard\
**Created:** [14 May 2019 07:07 UTC](https://discourse.nodered.org/t/form-data-to-database/11100 "2019-05-14T07:07:08Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 07:07 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/1 "2019-05-14T07:07:08Z")

</div>

I am trying to insert the form values in mysql using xampp server, but it is showing this error.  
please help.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bffaa3ec8a1e032e53477c9dae8ec5659a5e57e6.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2019 07:22 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/2 "2019-05-14T07:22:46Z")

</div>

The SQL you are executing is No Good. As the debug says, you are not providing a value for something that requires a value.

You should attach a debug to each node on your flow and inspect the output. That will help you narrow down the issue.

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 08:21 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/3 "2019-05-14T08:21:21Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/751cd42aef81ca92d9fde51878d316ed97f8c9fd.png) I am getting null value when my query is executing but form has data .please guide me where i am wrong

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 May 2019 08:51 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/4 "2019-05-14T08:51:38Z")

</div>

As you can see you are trying ti insert Emp\_Id with a value of null (first element of the array) and your database is set to not allow that.

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 08:53 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/5 "2019-05-14T08:53:06Z")

</div>

sir , i am providing the value but i don't know y it's taking null . please see the second output which is of form output.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 May 2019 09:09 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/6 "2019-05-14T09:09:39Z")

</div>

The form is sending an object and the sql wants an array - so your function is not providing that.

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 09:15 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/7 "2019-05-14T09:15:52Z")

</div>

so, how can we do that . how can we provide array instead of object.

---

<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:** [14 May 2019 09:42 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/8 "2019-05-14T09:42:07Z")

</div>

1. What does the query look like that you are building in the function node?

2. Where do you put this query? (see the info box for the `mysql` node)

3. change your debug nodes to display the `complete msg object`

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 09:46 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/9 "2019-05-14T09:46:45Z")

</div>

[{"id":"e8e5e50e.b83968","type":"mysql","z":"166ff6a7.0b0779","mydb":"6474c2f6.29a27c","name":"","x":570,"y":60,"wires":[["2b34346d.15f73c"]]},{"id":"6474c2f6.29a27c","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"silvan","tz":""}]  
here i attached my flow.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2019 10:48 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/10 "2019-05-14T10:48:51Z")

</div>

What I see is the form is passing your input as an object

```auto
{
id: "", name:"",Father_name:"",DOJ:""
}

```

From looking at your SQL INSERT statement you should be sending an array.

You need to convert the properties of the form input into an array.

off the opt of my head ...

```auto
var formData = msg.payload;
var dataForInsertQuery = [];
dataForInsertQuery.push(formData.id);
dataForInsertQuery.push(formData.name);
dataForInsertQuery.push(formData.Father_name);
dataForInsertQuery.push(formData.DOJ);

```

...should put you closer to a solution

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:07 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/11 "2019-05-14T11:07:41Z")

</div>

no, its not working

---

<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:** [14 May 2019 11:18 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/12 "2019-05-14T11:18:45Z")

</div>

Please show the debug output when something doesn’t work and a copy of the code you used. You could have made a typo....

Also you only provided the MySQL node not your complete flow.

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:23 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/13 "2019-05-14T11:23:57Z")

</div>

[{"id":"166ff6a7.0b0779","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"f105783c.907508","type":"ui\_form","z":"166ff6a7.0b0779","name":"","label":"","group":"1693ba1c.3fe0f6","order":4,"width":0,"height":0,"options":[{"label":"Emp\_id","value":"id","type":"text","required":true},{"label":"name","value":"name","type":"text","required":false}],"formValue":{"id":"","name":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":110,"y":180,"wires":[["6ffadafe.da5624","f542a33.433356"]]},{"id":"6ffadafe.da5624","type":"function","z":"166ff6a7.0b0779","name":"insert Query","func":"msg.topic="INSERT INTO test(Emp\_Id,name) VALUES (?,?)";\nmsg.payload=[msg.payload.Emp\_Id,msg.payload.name];\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":80,"wires":[["e8e5e50e.b83968","c21b9501.cc5fd8"]]},{"id":"e8e5e50e.b83968","type":"mysql","z":"166ff6a7.0b0779","mydb":"6474c2f6.29a27c","name":"","x":550,"y":60,"wires":[["2b34346d.15f73c"]]},{"id":"2b34346d.15f73c","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":260,"wires":},{"id":"f542a33.433356","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":230,"y":340,"wires":},{"id":"c21b9501.cc5fd8","type":"debug","z":"166ff6a7.0b0779","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":420,"y":240,"wires":},{"id":"1693ba1c.3fe0f6","type":"ui\_group","z":"","name":"test","tab":"478ee339.c9145c","order":1,"disp":true,"width":"6","collapse":false},{"id":"6474c2f6.29a27c","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"silvan","tz":""},{"id":"478ee339.c9145c","type":"ui\_tab","z":"","name":"puri","icon":"dashboard","disabled":false,"hidden":false}]  
this is the flow.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/28d2c0b8abbd158cbf8dbf14da70d505aadb13ea.png)

---

<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:** [14 May 2019 11:28 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/14 "2019-05-14T11:28:46Z")

</div>

Where did you come up with msg.payload.Emp\_id in your function?

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:32 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/15 "2019-05-14T11:32:09Z")

</div>

i am trying to send those value to my table . i used msg.payload because it used to send the output in array.

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:35 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/16 "2019-05-14T11:35:24Z")

</div>

@zenofmud sir now i am getting this error

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/0ae23d901a5bf00ec74d90510590c6c249c73274.png)

---

<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:** [14 May 2019 11:49 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/17 "2019-05-14T11:49:43Z")

</div>

Look at your debug output that is going into the function node. What are the names of the elements in msg.payload?

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:52 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/18 "2019-05-14T11:52:49Z")

</div>

okay. can you tell me how i can send form data as in array .

---

<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:** [14 May 2019 11:53 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/19 "2019-05-14T11:53:56Z")

</div>

What are the names of the items in msg.payload?  
What names are you using in the function node?  
Are they the same?

P.s. yes I could tell you the answer, but it’s better for you to figure it out yourself and learn something

---

<div class="post-metadata">

**Author:** ![purnima](https://avatars.discourse-cdn.com/v4/letter/p/49beb7/32.png) [@purnima](https://discourse.nodered.org/u/purnima)\
**Post date:** [14 May 2019 11:55 UTC](https://discourse.nodered.org/t/form-data-to-database/11100/20 "2019-05-14T11:55:49Z")

</div>

yes , they are same . the names are Emp\_Id and name.

[Next page](https://discourse.nodered.org/t/form-data-to-database/11100.md?page=2)
