# Need Help to Insert, Update and Delete Data from Node-RED Dashboard Inputs to the Database

**URL:** <https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545>\
**Category:** Dashboard\
**Created:** [13 July 2018 06:59 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545 "2018-07-13T06:59:11Z")\
**Posts on this page:** 15\
**Page:** 2

<div class="post-metadata">

**Author:** ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)\
**Post date:** [17 July 2018 08:36 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/22 "2018-07-17T08:36:55Z")

</div>

Yes, it's working. Thank you very much for your help.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2018 08:53 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/23 "2018-07-17T08:53:41Z")

</div>

Have you noticed that if you submit the text then just change the code and submit again then it does not work as only the code is sent? I see you have separately asked a question on how to link back from the submit to clear the fields, but if you want, it is possible to make it so that if you click again then all the current fields are sent not just the changed ones, if that better suits your needs.

---

<div class="post-metadata">

**Author:** ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)\
**Post date:** [17 July 2018 09:26 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/24 "2018-07-17T09:26:53Z")

</div>

Change which code? How to do clear the fields?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2018 09:36 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/25 "2018-07-17T09:36:34Z")

</div>

If you want it to send the latest values even when you have only changed one (such as the code) then you can use this

```auto
[{"id":"ab218375.33ee68","type":"ui_text_input","z":"acd8202b.36972","name":"name","label":"Name","group":"b7868331.17d03","order":1,"width":0,"height":0,"passthru":false,"mode":"text","delay":"300","topic":"name","x":95,"y":105,"wires":[["27e21385.7c9754"]]},{"id":"bae0ad4f.2ee728","type":"ui_text_input","z":"acd8202b.36972","name":"code","label":"Code","group":"b7868331.17d03","order":3,"width":0,"height":0,"passthru":false,"mode":"number","delay":"300","topic":"code","x":95,"y":185,"wires":[["27e21385.7c9754"]]},{"id":"d03aaabf.445658","type":"ui_button","z":"acd8202b.36972","name":"save-button","group":"b7868331.17d03","order":4,"width":0,"height":0,"passthru":false,"label":"Save","color":"","bgcolor":"","icon":"","payload":"{}","payloadType":"global","topic":"save-button","x":115,"y":225,"wires":[["27e21385.7c9754"]]},{"id":"6e7829cd.8f15a8","type":"ui_dropdown","z":"acd8202b.36972","name":"lastname","label":"","place":"Select Last Name","group":"b7868331.17d03","order":2,"width":0,"height":0,"passthru":false,"options":[{"label":"Rishan","value":1,"type":"num"},{"label":"Login","value":2,"type":"num"}],"payload":"","topic":"lastname","x":105,"y":145,"wires":[["27e21385.7c9754"]]},{"id":"7f8e1375.b697f4","type":"debug","z":"acd8202b.36972","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":576,"y":105,"wires":[]},{"id":"27e21385.7c9754","type":"join","z":"acd8202b.36972","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":295,"y":105,"wires":[["dccd7938.49472"]]},{"id":"dccd7938.49472","type":"switch","z":"acd8202b.36972","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"save-button","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":432.5,"y":105,"wires":[["7f8e1375.b697f4"]]},{"id":"b7868331.17d03","type":"ui_group","z":"","name":"Insert Data Test","tab":"54d30b5d.781dfc","order":1,"disp":true,"width":"6"},{"id":"54d30b5d.781dfc","type":"ui_tab","z":"","name":"Input Test","icon":"dashboard","order":3}]

```

If instead you want to clear the fields when the Save button is pressed then you will have to feed a message back (via appropriate Change nodes) to the inputs of the fields so that they are cleared when you press Save. If you do that then make sure the Pass Through checkbox is cleared on each field configuration.

@dceejay this is an example of where it would be useful to have a Retain Last Values setting in the Join node so it would not be necessary to use this rather kludgey workaround using a Switch node.

---

<div class="post-metadata">

**Author:** ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)\
**Post date:** [17 July 2018 09:54 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/26 "2018-07-17T09:54:44Z")

</div>

Okay. If like that, what I should set on the Change node?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [17 July 2018 10:45 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/27 "2018-07-17T10:45:28Z")

</div>

> [@rishanaziz](#):
>
> Okay. If like that, what I should set on the Change node?

Is that not being discussed in the other thread?

---

<div class="post-metadata">

**Author:** ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)\
**Post date:** [18 July 2018 02:48 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/28 "2018-07-18T02:48:42Z")

</div>

I'm not sure. I have another question. I need to check the database by query whether the entered data is exist on the table. If yes, we should prevent the user from inserting the data. If no, then we allow them to insert the data. How to do this?

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [18 July 2018 03:52 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/29 "2018-07-18T03:52:46Z")

</div>

Usually, this would be designed into the database table itself -- for instance, in MySQL I would set up a unique index on the column(s) I need, which prevents duplicate rows from being created. That would eliminate the need for your application to query before allowing them to do the insert (which is not atomic, and so could still allow two clients to insert the same data at the same time).

But this is more of a question on database design than node-red... and if you want to switch topics, you should start a new thread in order to make it easier for others to search for similar solutions later.

---

<div class="post-metadata">

**Author:** ![rishanaziz](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@rishanaziz](https://discourse.nodered.org/u/rishanaziz)\
**Post date:** [18 July 2018 06:15 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/30 "2018-07-18T06:15:05Z")

</div>

Okay. I think you're right. Thanks for helping.

---

<div class="post-metadata">

**Author:** ![tarihoran20](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@tarihoran20](https://discourse.nodered.org/u/tarihoran20)\
**Post date:** [3 May 2019 08:28 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/31 "2019-05-03T08:28:41Z")

</div>

hai risha, my name is reymond tarihoran. its good to hear that your syntax to input data to MySQL using node-red well worked. i'm wondering if you can show your syntax in Function node, about this part:

msg.topic="INSERT INTO test (name,lastname,code) VALUES (?,?,?)";  
msg.payload=[msg.payload.name,msg.payload.lastname,msg.payload.code];  
return msg;

i have some problem too.  
thank you for your help

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [3 May 2019 09:24 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/32 "2019-05-03T09:24:34Z")

</div>

Put a debug node showing the output of that function, and another showing the output of the sql node and post the results here please.

---

<div class="post-metadata">

**Author:** ![tarihoran20](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@tarihoran20](https://discourse.nodered.org/u/tarihoran20)\
**Post date:** [3 May 2019 09:50 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/33 "2019-05-03T09:50:46Z")

</div>

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

here the result I got

---

<div class="post-metadata">

**Author:** ![tarihoran20](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@tarihoran20](https://discourse.nodered.org/u/tarihoran20)\
**Post date:** [3 May 2019 09:53 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/34 "2019-05-03T09:53:40Z")

</div>

![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3634e883ba23c099320c952558a81bde1d05b170.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [3 May 2019 10:07 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/35 "2019-05-03T10:07:13Z")

</div>

The top debug shows that you are trying to insert VALUES that are undefined

(see the `(undefined,undefined)` bit in red)

You are trying to insert `msg.test1` and `msg.test3`

But your debug panel above shows that they are `msg.payload.test1` & `msg.payload.test3`

Theres a handy page in the docs that explain how to use the debug tooltips to get the correct path to any bit of data. It is worth reading...  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![tarihoran20](https://avatars.discourse-cdn.com/v4/letter/t/a587f6/32.png) [@tarihoran20](https://discourse.nodered.org/u/tarihoran20)\
**Post date:** [3 May 2019 10:38 UTC](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545/36 "2019-05-03T10:38:18Z")

</div>

thanks for information. i'll try

[Previous page](https://discourse.nodered.org/t/need-help-to-insert-update-and-delete-data-from-node-red-dashboard-inputs-to-the-database/1545.md?page=1)
