hi guys, I am not that much into SQL and was working on my first project and I had this error, I need your help, please
.If a value is a string, you need quotes around it. You have no quotes around the value of label so it thinks you are referring to a field in the table labelled DWD981
Some quick and basic SQL training will do you well.
Some other tips...
- Use prepared statements to avoid SQL injection (search forum)
- If you must use string concatenation to build your SQL, use "template literals" (search internet) - it will greatly simplify your code.
Hi sir, when i use quotes like this VALUES ("+ "' msg.payload.configuration.label '"+ ","+ "' msg.payload.configuration.nodeType '" +"," this is what i got
Attach a debug to output of function node & look at the SQL generated for yourself. You will see what you have done.
When you have done that, try this method instead...
msg.topic = `INSERT INTO tbl (a_string, another_string, a_number) VALUES ('${msg.payload.a_string}', '${msg.payload.another_string}', ${msg.payload.a_number}) `
^ note how strings are surrounded with single quotes & a number is not!
BUT: Also, as i said before...
If one of your strings has a single quote - you will get an error.
If someone enters BAD text, you could lose your database (SQL injection)
Okay, I will follow your instructions and thank you for your time.
i.e...
msg.topic = `INSERT INTO tbl (a_string, another_string, a_number) VALUES ('${msg.payload.a_string}', '${msg.payload.another_string}', ${msg.payload.a_number})`
thank you for your help sir
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.