Error: ER_BAD_FIELD_ERROR: Unknown column 'DWD981' in 'field list'

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...

  1. Use prepared statements to avoid SQL injection (search forum)
  2. 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)

1 Like

Okay, I will follow your instructions and thank you for your time.

Hi hope you're doing well i wanna know why i have this error ?

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})`

1 Like

thank you for your help sir

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