# Error: ER\_BAD\_FIELD\_ERROR: Unknown column 'DWD981' in 'field list'

**URL:** <https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802>\
**Category:** General\
**Created:** [18 March 2021 09:46 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802 "2021-03-18T09:46:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![med](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@med](https://discourse.nodered.org/u/med)\
**Post date:** [18 March 2021 09:46 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/1 "2021-03-18T09:46:12Z")

</div>

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

 ![error node 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/5/c51f43f4e336783ba88049ffbf566ae5d51c3d45.png) .

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 March 2021 09:53 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/2 "2021-03-18T09:53:54Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/47afc838fccd8305368ad7dbfa30857d0efe99ee.png)

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.

---

<div class="post-metadata">

**Author:** ![med](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@med](https://discourse.nodered.org/u/med)\
**Post date:** [18 March 2021 10:07 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/3 "2021-03-18T10:07:00Z")

</div>

Hi sir, when i use quotes like this VALUES ("+ "' msg.payload.configuration.label '"+ ","+ "' msg.payload.configuration.nodeType '" +"," this is what i got

 ![db](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/488ba14c37834e49de70dfc2aa2e21e02e08b942.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 March 2021 10:13 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/4 "2021-03-18T10:13:01Z")

</div>

> [@med](#):
>
> 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...

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

> [@Steve-Mcl](#):
>
> - 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.

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)

---

<div class="post-metadata">

**Author:** ![med](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@med](https://discourse.nodered.org/u/med)\
**Post date:** [18 March 2021 10:17 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/5 "2021-03-18T10:17:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![med](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@med](https://discourse.nodered.org/u/med)\
**Post date:** [23 March 2021 11:18 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/6 "2021-03-23T11:18:30Z")

</div>

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

 ![error node 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0a2ed2f6605121e231be5d0855816b968459484d.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 March 2021 11:22 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/7 "2021-03-23T11:22:43Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![med](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@med](https://discourse.nodered.org/u/med)\
**Post date:** [23 March 2021 11:31 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/8 "2021-03-23T11:31:00Z")

</div>

thank you for your help sir

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [22 May 2021 11:31 UTC](https://discourse.nodered.org/t/error-er-bad-field-error-unknown-column-dwd981-in-field-list/42802/9 "2021-05-22T11:31:47Z")

</div>

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