# TypeError in node-red when trying to post the data form flutter project

**URL:** <https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606>\
**Category:** General\
**Created:** [14 March 2021 08:36 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606 "2021-03-14T08:36:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![y.star](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/y.star/32/30480_2.png) [@y.star](https://discourse.nodered.org/u/y.star)\
**Post date:** [14 March 2021 08:36 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/1 "2021-03-14T08:36:19Z")

</div>

Hi, I'm quite new to node-red. I'm trying to post the data from my flutter project to database via node-red but I got this error. (However, the type of order\_status\_id is set as integer both in database and flutter project.)

![Screen Shot 2021-03-14 at 15.28.43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/2797202e43d2a98edd418c6084b7817955cabf36.jpeg)

Below this is my flow on node red.

 ![Screen Shot 2021-03-14 at 15.29.55](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/398efa520dbbd90fa5da7c5c04902d9a46f30216.jpeg)

Function in node-red

```auto
var customer_id = msg.payload.customer_id;
var order_status_id = msg.paylod.order_status_id;
var address = msg.paylod.address;
var date = msg.paylod.date;
var total_amount = msg.paylod.total_amount;
var delivery_fee = msg.paylod.delivery_fee;
var delivery_method = msg.paylod.delivery_method;
var receiver_name = msg.paylod.receiver_name;
var sub_total = msg.paylod.sub_total;
var postcode = msg.paylod.postcode;
var time = msg.paylod.time;

var sql = "";
var template = "insert into orders (order_id,customer_id,order_status_id,address,date,total_amount,delivery_fee,delivery_method, receiver_name,sub_total, postcode, time) ";
template += "values(null,'o1','o2','o3','o4','o5','o6','o7','o8','o9','o10','o11');";

for(var i=0;i<items.length;i++){
    var cp = template;
cp = cp.replace('o1',customer_id);
cp = cp.replace('o2',order_status_id);
cp = cp.replace('o3',address);
cp = cp.replace('o4',date);
cp = cp.replace('o5',total_amount);
cp = cp.replace('o6',delivery_fee);
cp = cp.replace('o7',delivery_method);
cp = cp.replace('o8',receiver_name);
cp = cp.replace('o9',sub_total);
cp = cp.replace('o10',postcode);
cp = cp.replace('o11',time);
sql += cp;
}

msg.topic = sql;
return msg;

```

Function in flutter:

````auto
void makeOrder() {
    String url = order_url;

    ProductOrder order = ProductOrder(
        customer_id:1,
        order_status_id: 1,
        address: _address,
        date: _date,
        total_amount: _grandTotal,
        delivery_fee: _del_fee,
        delivery_method: _deli,
        receiver_name: _receiver_name,
        sub_total: _sub_total,
        postcode: _postcode,
        time: _time,
    );

    var data = json.encode(order.toJson());
    print(data);
    http.post(url, body: data, headers: {"Content-Type": "application/json"})
        .then((value) => print(value));
  }//ef```
````

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 March 2021 09:07 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/2 "2021-03-14T09:07:37Z")

</div>

Hi,  
which version of the mysql node did you install - If just yesterday v0.1.2 had a regression in that broke it - please make sure you have version 0.1.3.

---

<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:** [14 March 2021 09:14 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/3 "2021-03-14T09:14:35Z")

</div>

> [@y.star](#):
>
> `order_status_id = msg.paylod.order_status_id`

Spot the deliberate spelling mistake ^

Ps, you copy and pasted that typo a few times.

Also, where does `items` come from in that for loop?

Lastly, using string replace is not a good idea. It is a time bomb. Suppose someone entered a post code of `no7 1ab` guess what would happen.

You would be far better off with prepared statements.

If you don't wanna go down that path then at least change the string replace calls with a single is string template literal e.g...

```auto
sql = `insert into orders (col1) values (${value1});`

```

---

<div class="post-metadata">

**Author:** ![y.star](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/y.star/32/30480_2.png) [@y.star](https://discourse.nodered.org/u/y.star)\
**Post date:** [14 March 2021 09:21 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/4 "2021-03-14T09:21:53Z")

</div>

How can I check the version of it?

---

<div class="post-metadata">

**Author:** ![y.star](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/y.star/32/30480_2.png) [@y.star](https://discourse.nodered.org/u/y.star)\
**Post date:** [14 March 2021 09:22 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/5 "2021-03-14T09:22:45Z")

</div>

I've checked so many times but didn't see any spelling mistake. 😭

---

<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:** [14 March 2021 09:28 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/6 "2021-03-14T09:28:04Z")

</div>

payload not paylod

Ps I updated that post with additional info. Please read it again.

---

<div class="post-metadata">

**Author:** ![y.star](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/y.star/32/30480_2.png) [@y.star](https://discourse.nodered.org/u/y.star)\
**Post date:** [14 March 2021 09:37 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/7 "2021-03-14T09:37:15Z")

</div>

It's working now! I firstly checked only the word order\_status\_id, so I didn't see the word "payload" as it's misspelled. 😅 Thanks you so much for the suggestion above and helping me fixing this.

---

<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:** [14 March 2021 09:40 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/8 "2021-03-14T09:40:19Z")

</div>

> [@Steve-Mcl](#):
>
> Lastly, using string replace is not a good idea. It is a time bomb. Suppose someone entered a post code of `no7 1ab` guess what would happen.

Do you know what will happen?

When the code his this line

```auto
cp = cp.replace('o7',delivery_method);

```

It will find `o7` in the middle of the address & will put the delivery method in the middle of the post code.

That issue exists for every one of the fields.

Not only that, you are wide open to SQL injections.

Do yourself a favour, read the docs for the node & learn how to do prepared statement.

---

<div class="post-metadata">

**Author:** ![y.star](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/y.star/32/30480_2.png) [@y.star](https://discourse.nodered.org/u/y.star)\
**Post date:** [14 March 2021 09:51 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/9 "2021-03-14T09:51:28Z")

</div>

ohh, I've never known it before. I will learn more about it, thanks a lot. 🙏

---

<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:** [28 March 2021 09:52 UTC](https://discourse.nodered.org/t/typeerror-in-node-red-when-trying-to-post-the-data-form-flutter-project/42606/10 "2021-03-28T09:52:20Z")

</div>

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