Query to write data to mySQL database(error)

Hi. kindly help me cross check what seems to be the error here. I want to pass an input string value to "msg.text" variable and i want it to write on mySQL database. my "msg.payload" works fine, the issue lies only on the "msg.text".


Does msg.text actually have a value?

Use a debug node (set to show complete msg) BEFORE the function node.
add node.warn(msg.text) in your function BEFORE setting msg.topic

Lastly - it is strongly recommended you use prepared queries / parameters instead of generating a SQL Query string (it is unsafe / prone to SQL injection) - read the node-red-node-mysql help to see how to use parameters.

this "msg.text" takes in the string character from whatever i input on the dashboard. I tested on a separate flow and this works fine. but this problem arises when i try to included it in the query.

I tried changing the debug node to display "all msg object" and i manage to get the msg.text data as "a" string value.


This time yes, but your first error was different - it showed undefined so I can pretty much guarantee msg.text was NOT present.

this time you have a different error and it is coming from a different node (i can see this one is named sends_data_to_SQL where as the previous error came from an unnamed node).

For reference: toFixed only works on numbers (you must be calling toFixed on a string or something else inside sends_data_to_SQL). Use the same tips I showed you previously to determine what that is.

i only called ToFixed() for msg.payload which is a number. and it works as shown.

sends_data_toSQL is basically a function node which contains the query as shown in the image above.


I say what I see!

I'm sorry, but you are not clear and not sharing enough related info (I dont even know the arrangement of your flows) so I cant really help without context!

hi. So sorry, i will try to attach my whole flow here next week. office is closed on weekends.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.