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

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

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.

Change which code? How to do clear the fields?

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

[{"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.

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

Is that not being discussed in the other thread?

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?

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.

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

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

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.

here the result I got

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

thanks for information. i'll try