# 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:** 17
**Page:** 5

<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 09:47 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/81 "2020-07-21T09:47:07Z")

</div>

Sir I want that only valid entered rfid can trigger the switches and updated data happen only in their columns.

---

<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 09:47 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/82 "2020-07-21T09:47:55Z")

</div>

Yes Sir. only that person can use their own dashboards

---

<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 09:48 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/83 "2020-07-21T09:48:59Z")

</div>

For e.g i entered E1234562 then i triggered switch then update only E1234562 column  
not in E1234561

---

<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 10:14 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/84 "2020-07-21T10:14:42Z")

</div>

Yes Sir ,What alternative I can apply so that i can store my open/close string into my database wrt my entered RFID

---

<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 11:46 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/85 "2020-07-21T11:46:00Z")

</div>

I am waiting for your reply anyone please suggest me some another method please,as i have to submit my report.

---

<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: [21 July 2020 11:48 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/86 "2020-07-21T11:48:26Z")

</div>

> [@shipra](#):
>
> as i have to submit my report.

Is this a school assignment?

---

<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 11:49 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/87 "2020-07-21T11:49:47Z")

</div>

Its my company project I really have to update them.

---

<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: [21 July 2020 12:01 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/88 "2020-07-21T12:01:41Z")

</div>

So you have been asked to complete this project with no knowledge of Node-RED or SQL?

I will try to explain how you might be able to solve it. I cannot promise this will work because I still don't think you have told use what you really want.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/5/a5111deaee50b880913a2224f8a9b5b961421373.png)

At the moment when a message arrives over MQTT, you are passing it to two separate flows - the 'set msg.id' node, and the 'template' node flow. So you now have two separate messages flowing through.

The first of those messages (the set msg.id branch) will go straight to the `update_template` node. At that point, the message will have a payload of `E1234562` and an id of `E1234562`, so the SQL statement will be generated with that value in both positions. That is not what you want.

The second of those messages will pass through the flow that checks to see if it exists, then setting payload to the valid/invalid messages. You then, for some reason, pass them to a pair of dashboard switch nodes.

At some point you click the dashboard switch node and it will send its value (the valid/invalid payload) to the `update_template` node. But at this point, that message no longer has the original RFID id attached to it (msg.id was never set in this branch of the flow), so the SQL statement is not correct.

TO fix it...

1. delete the set msg.id Change node and its wire going to the `update_template` node.

2. add a new Change between the MQTT node and the first `template` node. Configure that node to `set flow.id to msg.payload`. Note this is setting the **flow** context variable. I'm not going to explain what context is - you can go read the documentation.

3. Add a Change node before the `update_template` node configured to `set msg.id to flow.id` - this will copy the last stored value of `flow.id` back onto the message.

4. Rewire both of the Dashboard switch nodes so they go into this new Change node.

---

<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 12:10 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/89 "2020-07-21T12:10:10Z")

</div>

> [@knolleary](#):
>
> Add a Change node before the `update_template` node configured to `set msg.id to flow.id` - this will copy the last stored value of `flow.id` back onto the message.

This node first connects to ?

---

<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: [21 July 2020 12:24 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/90 "2020-07-21T12:24:51Z")

</div>

At the moment you have:

```auto
ui_switch -\
            > - Template
ui_switch -/

```

You want:

```auto
ui_switch -\
            > - Change -> Template
ui_switch -/

```

---

<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 12:24 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/91 "2020-07-21T12:24:52Z")

</div>

Sir I am a fresher I have learned Node red in CDAC but i got interest in node red so i opted this project so that i can get more knowledge and learning,and when i saw this forum i really got more interest in Node red .Thats why i am asking no personal intentions to trouble you .  
Sorry once again if any line is wrong.

---

<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 12:28 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/92 "2020-07-21T12:28:05Z")

</div>

> [@knolleary](#):
>
> `set flow.id to msg.payload` .

This showing property error

---

<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: [21 July 2020 12:28 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/93 "2020-07-21T12:28:56Z")

</div>

> [@shipra](#):
>
> This showing property error

Share a screenshot of how you have configured the node.

---

<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 12:30 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/94 "2020-07-21T12:30:17Z")

</div>

![p](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b99f2d67e70c92f558ec58e560326552670dccf2.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: [21 July 2020 12:31 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/95 "2020-07-21T12:31:39Z")

</div>

It looks like you have a space character after `id`.

---

<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 12:38 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/96 "2020-07-21T12:38:05Z")

</div>

Sir,how can I say thanks i dont know .thank you so much it is now working  
Thank You 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: [4 August 2020 12:38 UTC](https://discourse.nodered.org/t/copying-my-door-control-status-back-to-my-mysql-databse/30383/97 "2020-08-04T12:38:16Z")

</div>

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

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