# Update a MYSQL DB Entry

**URL:** <https://discourse.nodered.org/t/update-a-mysql-db-entry/38972>\
**Category:** General\
**Created:** [11 January 2021 19:48 UTC](https://discourse.nodered.org/t/update-a-mysql-db-entry/38972 "2021-01-11T19:48:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![paco1503](https://avatars.discourse-cdn.com/v4/letter/p/eada6e/32.png) [@paco1503](https://discourse.nodered.org/u/paco1503)\
**Post date:** [11 January 2021 19:48 UTC](https://discourse.nodered.org/t/update-a-mysql-db-entry/38972/1 "2021-01-11T19:48:24Z")

</div>

Hey, again a noob question ^^  
i tried 2 put something into my sql DB and it worked

function:  
var frisch = msg.count;  
query = `INSERT INTO Wasser(Stand) VALUES("`+frisch+`");`;  
msg.topic = query;  
return msg;

but now i want, that he updates "Stand" with every new entry....

var frisch = msg.count;  
query = `UPDATE Wasser(Stand) VALUES("`+frisch+`") WHERE 1;`;  
msg.topic = query;  
return msg;

this was my try, but it didnt worked... maybe my DB has the wrong settings or something. Can someone help me and explain the mistake i am doing? thanks! 🙂

---

<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:** [11 January 2021 20:05 UTC](https://discourse.nodered.org/t/update-a-mysql-db-entry/38972/2 "2021-01-11T20:05:12Z")

</div>

The variable `query` value you are settng is supposed to be a string so is missing quotes around it. E.g...

```javascript
var query = 'INSERT INTO Wasser(Stand) VALUES("' + frisch + '");';

```

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 January 2021 22:20 UTC](https://discourse.nodered.org/t/update-a-mysql-db-entry/38972/3 "2021-01-11T22:20:29Z")

</div>

There is some useful info on SQL here:

[SQL UPDATE Statement (w3schools.com)](https://www.w3schools.com/sql/sql_update.asp)

and here:

[MySQL :: MySQL 8.0 Reference Manual :: 13.2.13 UPDATE Statement](https://dev.mysql.com/doc/refman/8.0/en/update.html)

Your update command isn't quite right but you are close.

Don't forget that if you want to update a record, you have to select the right row with the WHERE part. How you construct the WHERE is dependent on what fields (columns) you have in the db table.

You will probably want a tool that gives you a user interface to your MySQL db.

---

<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:** [12 March 2021 22:20 UTC](https://discourse.nodered.org/t/update-a-mysql-db-entry/38972/4 "2021-03-12T22:20:32Z")

</div>

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