# Http request send data format

**URL:** <https://discourse.nodered.org/t/http-request-send-data-format/74041>\
**Category:** General\
**Tags:** database, function-node\
**Created:** [22 January 2023 08:48 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041 "2023-01-22T08:48:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [22 January 2023 08:48 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/1 "2023-01-22T08:48:00Z")

</div>

hi , I try to send sensors data to  
db with http request node , connection with db is ok ,New record created successfully. but data is empty at db , i think my problem is how i send data :  
{"sensor":"ran","location":"iran","value1":"60","value2":"60"}

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/5/f55d4422ff1568a1a6267d8b296df894f16cb16d.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9fb585c6dc4d0a1a165c855eb7b26833a10ed611.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/0/808c349723f6bfc50b2a65a337a152c939315efe.png)

---

<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:** [22 January 2023 14:17 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/2 "2023-01-22T14:17:22Z")

</div>

Without sharing what the db is or how your request node is configured or what table schema your data uses, I'm not sure what you expect of people on the forum?

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [22 January 2023 14:45 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/3 "2023-01-22T14:45:37Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/89433eb12f56e5d7c5a5408103378a950be37602.png)

and this is my php 🙂

```auto
if ($_SERVER["REQUEST_METHOD"] == "POST") {
   
   
        $sensor = test_input($_POST["sensor"]);
        $location = test_input($_POST["location"]);
        $value1 = test_input($_POST["value1"]);
        $value2 = test_input($_POST["value2"]);
       
        
        // Create connection
       
        require_once ('connect_db.php'); 
        
        $sql = "INSERT INTO sensor_data(sensor, location, value1, value2)
        VALUES ('" . $sensor . "', '" . $location . "', '" . $value1 . "', '" . $value2 . "')";
        
        if ($conn->query($sql) === TRUE) {
            echo "New record created successfully";
        } 
        else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
    
        $conn->close();
 

}
else {
    echo "No data posted with HTTP POST.";
}

function test_input($data) {
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    return $data;
}

```

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [22 January 2023 15:29 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/4 "2023-01-22T15:29:13Z")

</div>

> [@sahar](#):
>
> ` echo "New record created successfully";`

Perhaps you should return the actual sql statement so that you can see what it did.

---

<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:** [22 January 2023 17:46 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/5 "2023-01-22T17:46:21Z")

</div>

That didn't answer any of the questions I said needed answering.

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 07:09 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/6 "2023-01-23T07:09:43Z")

</div>

thank you , I did it but again db values return null

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/a/7a7769207099a4e7ce2295b92d06ffb1d6bc4762.png)  
i think the problem is how and which format I send data ? isn't it?  
I will appreciate you if you help to solve that

---

<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:** [23 January 2023 08:51 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/7 "2023-01-23T08:51:23Z")

</div>

I think the obvious (Node-RED centric) question is, why not simply use the `node-red-node-mysql` node (instead of having a PHP endpoint/app) and do it completely in Node-RED?

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 January 2023 10:01 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/8 "2023-01-23T10:01:42Z")

</div>

While it was good that you shared a screen shot of your `http request` node, no-one can read the complete value of the 'URL' option url:

 ![http_request](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/7/477cc7b567fa0030911979549954a671f0ab1eab.jpeg)

Please export that node and paste the results to a reply.

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:05 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/9 "2023-01-23T10:05:42Z")

</div>

> [@zenofmud](#):
>
> Please export that node and paste the results to a reply.

this is the complete of url

[http://www.tekbin.lifeandbusiness.ir/sahar/php/post-esp-data.php](http://www.tekbin.lifeandbusiness.ir/sahar/php/post-esp-data.php)

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:08 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/10 "2023-01-23T10:08:36Z")

</div>

thank you , but mysql is located at web server and needs remote access connection , and it is impossible to have it. so I guess i have to use http !

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 January 2023 10:09 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/11 "2023-01-23T10:09:43Z")

</div>

Short of doing all this in Node RED as @Steve-Mcl said.

Maybe echo out the `$_POST` - to ensure you are actually receiving it.  
if you are, then the problem maybe `test_input` or something else on the PHP side?

```php

<?php
 print_r($_POST);
?>

```

EDIT

> but mysql is located at web server

i see 😅

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:10 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/12 "2023-01-23T10:10:37Z")

</div>

```auto
[
    {
        "id": "051e1f903d57ec87",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "f4909f0e23246419",
        "type": "change",
        "z": "051e1f903d57ec87",
        "name": "prepared feild",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "{\t \"sensor\":\"ran\",\t \"location\":\"iran\",\t \"value1\":\"60\",\t \"value2\":\"60\"\t}",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "header.Content-Type",
                "pt": "msg",
                "to": "application/x-www-form-urlencoded",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 460,
        "y": 200,
        "wires": [
            [
                "787bbfff8dff5524",
                "5b7630f82a96e09a"
            ]
        ]
    },
    {
        "id": "5b7630f82a96e09a",
        "type": "http request",
        "z": "051e1f903d57ec87",
        "name": "",
        "method": "POST",
        "ret": "txt",
        "paytoqs": "ignore",
        "url": "http://www.tekbin.lifeandbusiness.ir/sahar/php/post-esp-data.php",
        "tls": "",
        "persist": false,
        "proxy": "",
        "authType": "",
        "x": 680,
        "y": 220,
        "wires": [
            [
                "af9a131e0dd59404"
            ]
        ]
    },
    {
        "id": "787bbfff8dff5524",
        "type": "debug",
        "z": "051e1f903d57ec87",
        "name": "SD2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 140,
        "wires": []
    },
    {
        "id": "af9a131e0dd59404",
        "type": "debug",
        "z": "051e1f903d57ec87",
        "name": "SD3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 800,
        "y": 340,
        "wires": []
    },
    {
        "id": "45833ea2d49495ed",
        "type": "inject",
        "z": "051e1f903d57ec87",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 110,
        "y": 260,
        "wires": [
            [
                "f4909f0e23246419"
            ]
        ]
    }
]

```

---

<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:** [23 January 2023 10:11 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/13 "2023-01-23T10:11:50Z")

</div>

Forgetting the "Web Server" that provides an endpoint for your database for one second - are the Node-RED server and the mySQL database both on the same internal infrastructure/network?

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:15 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/14 "2023-01-23T10:15:49Z")

</div>

no they aren't.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [23 January 2023 10:20 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/15 "2023-01-23T10:20:33Z")

</div>

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<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:** [23 January 2023 10:24 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/16 "2023-01-23T10:24:13Z")

</div>

I do hope your data isn't private in any way. I also hope that, if you use a userid/password on that site that you don't use it anywhere else. If you don't use a uid/password, I trust that you don't care that anyone on the Internet could post to the db?

This is because you are connecting over the Internet to a web service without using TLS encryption (HTTPS). That means that you should assume that any id/password has been compromised due to interception.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 January 2023 10:24 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/17 "2023-01-23T10:24:36Z")

</div>

> [@marcus-j-davies](#):
>
> Maybe echo out the `$_POST` - to ensure you are actually receiving it.  
> if you are, then the problem maybe `test_input` or something else on the PHP side?
> 
> ```auto
> <?php
> print_r($_POST);
> ?>
> 
> ```

With all the input, this might have been missed

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:34 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/18 "2023-01-23T10:34:06Z")

</div>

this is just for test and it doesnt have important data , thank you for you attention

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 January 2023 10:48 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/19 "2023-01-23T10:48:06Z")

</div>

Another observation....

`header.Content-Type`

Should be  
`headers.Content-Type`

`header` should be be plural

Its very possible, the http request node, is submitting a JSON formatted body, and not ` x-www-form-urlencode`

Therefore correct the `header` key or use PHP's `json_decode` method

example: `json_decode(file_get_contents('php://input'));`

---

<div class="post-metadata">

**Author:** ![sahar](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sahar/32/86660_2.png) [@sahar](https://discourse.nodered.org/u/sahar)\
**Post date:** [23 January 2023 10:58 UTC](https://discourse.nodered.org/t/http-request-send-data-format/74041/20 "2023-01-23T10:58:29Z")

</div>

it really work . thank you

[Next page](https://discourse.nodered.org/t/http-request-send-data-format/74041.md?page=2)
