# Copying my Door control status back to my Mysql databse

**URL:** https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383
**Category:** General
**Created:** [20 July 2020 09:03 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383 "2020-07-20T09:03:04Z")
**Posts on this page:** 20
**Page:** 3

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 14:45 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/41 "2020-07-20T14:45:44Z")

</div>

Hi @shipra, it's hard to provide more help without knowing which part you are struggling with.

We are trying to help you learn how to do this rather than just give you a fully working solution that you don't understand.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 14:48 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/42 "2020-07-20T14:48:19Z")

</div>

Change node where can i take that ,that part i searching Sir

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 14:56 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/43 "2020-07-20T14:56:06Z")

</div>

> [@shipra](#):
>
> Change node where can i take that ,that part i searching S

Do you understand **why** I suggest adding a Change node? If you understand **why** then the answer to **where** should be clear.

So let me repeat what I said:

> From what I recall of the previous thread, you start with the ID in `msg.payload` but it gets overwritten when you do the database lookup.

> In which case, I suggest you add a Change node after the MQTT node, at the start of the flow,

Let me try to explain that again.

At the moment, you have the ID in `msg.payload` when it comes out of the MQTT node.

You then pass it to a Template node where you build an SQL query in `msg.topic` to lookup the ID in the table.

You then pass that to the mysql node to run the query. That node puts its result in `msg.payload`. This **overwrites** the old value of `msg.payload`, so the message no longer contains the ID.

Your flow looks like:

```auto
MQTT -> Template -> MySQL -> ....

```

So you need to find a way to keep the ID on the message. The best way of doing that is to _copy_ its value to a different message property that will not get overwritten by the other nodes.

You can do that with the Change node:

```auto
MQTT -> Change -> Template -> MySQL -> ...

```

And configure that Change node to `set msg.id to msg.payload`.

You should then find `msg.id` contains the RFID value later on in your flow - use a Debug node to check that.

If you don't understand any of that, then please try to explain what part you don't understand.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 15:09 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/44 "2020-07-20T15:09:47Z")

</div>

![ggg](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9ffe26fb9245a46d6a2b77e4a258d22539dff932.png) ![jj](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/9580b500d466b502eec23ffb47003b273886c200.png)

yes i have tried this ,Sir check ones and suggest

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 15:10 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/45 "2020-07-20T15:10:44Z")

</div>

No, you have not tried what I said.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 15:16 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/46 "2020-07-20T15:16:42Z")

</div>

change node to connect with template then database ![k](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/8/c800bbd67c9bf612f151c2456d4930df7838202f.png)

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 15:20 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/47 "2020-07-20T15:20:46Z")

</div>

That is still not what I said.

You need to add a Change node in between the MQTT and Template nodes.

You have done that, but you have left the wire from the MQTT node to the Template node. Delete that wire.

Also, you have not configured the Change node as I suggested. You have configured it to **Move** the property. If you move it, then you will break the flow because the Template node needs `msg.payload` to have the ID in it. This is why I said to configure it as `set msg.id to msg.payload`

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 15:25 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/48 "2020-07-20T15:25:15Z")

</div>

![n](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/613806dcc5e531f3c17e9baa67f9a33e0f582e20.png)

 ![nn](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5362d9e6526a8a608e90480257b9d7d7a8c9bd53.png)

Check ones

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 15:27 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/49 "2020-07-20T15:27:50Z")

</div>

As usual, you are pasting screenshots of Debug without any explanation. I have no idea if that is right or not. But what do **you** think? Does it look right to you?

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 15:29 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/50 "2020-07-20T15:29:07Z")

</div>

7/20/2020, 8:58:05 PM[node: debug3](http://127.0.0.1:1880/?#)

RFID : msg : Object

object

topic: "RFID"

payload: "E1234562"

qos: 1

retain: false

\_msgid: "6e46eb3f.f2a364"

id: "E1234562"

/////Yes i have stored rfid into an id

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 15:30 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/51 "2020-07-20T15:30:34Z")

</div>

Okay... so what do you think you need to do next?

Hint: modify your SQL statement to include `msg.id` where you have the RFID hardcoded.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [20 July 2020 16:03 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/52 "2020-07-20T16:03:35Z")

</div>

UPDATE rfid1  
set Door\_Status='{{payload}}'  
WHERE rfidno='{{msg.id}}';

/// not updating

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [20 July 2020 16:16 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/53 "2020-07-20T16:16:35Z")

</div>

```auto
UPDATE rfid1
set Door_Status='{{payload}}'
WHERE rfidno='{{msg.id}}';

```

You know you can insert the value of `msg.payload` by using `{{payload}}`. So how do you think you can insert the value of `msg.id`?

Can you spot your mistake?

It's `{{id}}` - you don't need the `msg.` part as you can _already_ see from the `payload` case that works.

---

<div class="post-metadata">

### Author: ![Nodi.Rubrum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/nodi.rubrum/32/107482_2.png) [@Nodi.Rubrum](https://discourse.nodered.org/u/Nodi.Rubrum)
#### Post date: [20 July 2020 19:24 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/54 "2020-07-20T19:24:17Z")

</div>

Just a design question... to you want to replace the same record over and over with current status? Or keep a history of the status changes? I did something similar some time ago, using python and door sensor, but I kept a history of the status changes using INSERT not UPDATE query, then used a SELECT query (for last/newest record in table) to refresh the UI as applicable.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [21 July 2020 04:58 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/55 "2020-07-21T04:58:42Z")

</div>

Sir i have done this RFID-----\>Change-----\>template node right  
but after entering E1234562 it is showing CR\_FAIL ,why ? as my database has E1234562 Please Suggest.

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [21 July 2020 05:18 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/56 "2020-07-21T05:18:05Z")

</div>

its no updating in database Sir.

 ![ll](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f62d61ee6d08fd3b8347c34dfb00d2d02408437e.png)

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [21 July 2020 05:31 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/57 "2020-07-21T05:31:04Z")

</div>

I want changed status every time Sir .please help I am not getting updated data in my database

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [21 July 2020 05:52 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/58 "2020-07-21T05:52:13Z")

</div>

Please anyone help ...I really need help.Thank You

---

<div class="post-metadata">

### Author: ![shipra](https://avatars.discourse-cdn.com/v4/letter/s/71c47a/32.png) [@shipra](https://discourse.nodered.org/u/shipra)
#### Post date: [21 July 2020 06:09 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/59 "2020-07-21T06:09:48Z")

</div>

![kl](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/e/2e5a5d0401c0ae7623d0c6ec3c753ab13717f906.png)  
Sir I really want help. Why i am not getting updated data .  
As i have searched google for this issue but haven't got anything.  
Sir please suggest me where i am wrong

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [21 July 2020 07:35 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/60 "2020-07-21T07:35:20Z")

</div>

Can you explain _why_ you want to store the current value in the database? Once you succeed in getting it stored what are you going to do with it? I ask because it is unusual just to record current status in a database like this and I wonder whether there is a better way achieve your final solution.

[Previous page](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383.md?page=2)

[Next page](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383.md?page=4)
