# Downloading csv file generated by MySQL database after pressing a form button

**URL:** <https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486>\
**Category:** General\
**Created:** [12 August 2020 17:05 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486 "2020-08-12T17:05:02Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [21 August 2020 18:58 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/21 "2020-08-21T18:58:26Z")

</div>

maybe because your 'simulated' data doesnt match the 'real' context.

send us a screenshot of the context data from your real flow .. expanded so we can see the whole structure pls

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:02 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/22 "2020-08-21T19:02:22Z")

</div>

![as](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d65d91bb07c479665e505893d98af69eb74775d.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [21 August 2020 19:04 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/23 "2020-08-21T19:04:13Z")

</div>

i think i found the issue .. you need an extra space infront of VALUES in sql query .. try this  
because your sql resolves to

`"INSERT INTO Andadores (ID_and,ID_pac,Inicio)VALUES (54,26,2020-7-1)"`

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:07 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/24 "2020-08-21T19:07:24Z")

</div>

Extra space where? My SQL query its the following, I see it has the spaces. Maybe I am not understanding you.

 ![sql](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddee4b41ba72656a6f64c9312c4f9891a2dfdaea.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [21 August 2020 19:08 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/25 "2020-08-21T19:08:53Z")

</div>

Like this :

```auto
msg.topic = "INSERT INTO Andadores (ID_and,ID_pac,Inicio)"+ " VALUES ("+id_and+","+idpacs+","+inicio+")";
return msg;

```

the space outside the " " doesnt count

an even cleaner syntax is this .. using backticks ` .. not to be confused with single quotes '

```auto
msg.topic = `INSERT INTO Andadores (ID_and,ID_pac,Inicio) VALUES (${id_and},${idpacs},${inicio})`;

```

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:11 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/26 "2020-08-21T19:11:58Z")

</div>

Thanks!  
But no, it does not work. The issue its:

> idpacs = idpacs.payload[0];

If I don´t use that, then it returns the message to the output but well, the value its the object Object thing that is ruining it.

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:14 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/27 "2020-08-21T19:14:28Z")

</div>

Thing is, I have used that line outside the flow Im trying to make work and it access to the value ID\_pac, which is the goal. I don´t know what is happening.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [21 August 2020 19:15 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/28 "2020-08-21T19:15:55Z")

</div>

> [@SinZapatillas](#):
>
> idpacs = idpacs.payload[0];

i thought it should have been

```auto
idpacs = idpacs.payload[0].ID_pac // here

```

what did you try ?  
because in the simulation it works

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:24 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/29 "2020-08-21T19:24:38Z")

</div>

I have found the solution.

> var idpacs = flow.get("flow");  
> idpacs = idpacs[0].ID\_pac;

Once you store the context variable in the variable, you no longer need the .payload because now its called idpacs... I have been trying it in an independent flow to check what was happening until I realised it.

Thansk for the help. This was driving me crazy.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [21 August 2020 19:37 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/30 "2020-08-21T19:37:04Z")

</div>

cool .. im glad you found it

im not sure if you know this but if you want to check your context ..  
you go in the upper top right corner triangle and choose Context Data and refresh for the 'Flow'

![Screenshot_2020-08-21 Node-RED 192 168 1 160](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efdff98fd49c7676f9a99071be1f0702ce64afca.png)

---

<div class="post-metadata">

**Author:** ![SinZapatillas](https://avatars.discourse-cdn.com/v4/letter/s/ee59a6/32.png) [@SinZapatillas](https://discourse.nodered.org/u/SinZapatillas)\
**Post date:** [21 August 2020 19:39 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/31 "2020-08-21T19:39:06Z")

</div>

No I didn´t know it..it´s my first time doing this. Thanks!!

---

<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:** [20 October 2020 19:39 UTC](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486/32 "2020-10-20T19:39:13Z")

</div>

Closed on 20 October 2020 19:39 UTC

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

[Previous page](https://discourse.nodered.org/t/downloading-csv-file-generated-by-mysql-database-after-pressing-a-form-button/31486.md?page=1)
