# HTTP POST GET problem probably the server

**URL:** <https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601>\
**Category:** General Guidance\
**Created:** [June 4, 2023, 11:45pm UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601 "2023-06-04T23:45:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 4, 2023, 11:45pm UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/1 "2023-06-04T23:45:54Z")

</div>

[shit.ino](https://forum.arduino.cc/uploads/short-url/kn8BqEKd4VtL8HMpjuERW0vEBJ3.ino) (2.7 KB)  
hello, i've been trying to send the temperature and humidity values from arduino to php, but no luck since, the programs looks perfect but i can't seem to understand why the server can'tretrive the values. maybe there's a mistake. help pls

````arduino
<?php

if (empty($_GET['t']) || empty($_GET['h'])) {
    // If temperature or humidity values are empty, send an error message
    echo "Error: Temperature and humidity values not received";
} else {
    $temp = $_GET['t']; // Retrieve the 't' value from the POST request
    $hum = $_GET['h']; // Retrieve the 'h' value from the POST request

    // Print the received values
    echo "Received temperature: " . $temp . "<br>";
    echo "Received humidity: " . $hum . "<br>";

    $base = mysqli_connect("localhost", "root", "ruth", "maisondannel"); // Connect to the MySQL database
    $sql = "INSERT INTO stupid (temp, hum) VALUES (" . $temp . ", " . $hum . ");"; // Create the SQL query
    mysqli_query($base, $sql); // Execute the SQL query
    mysqli_close($base); // Close the database connection

    // Send a success message
    echo "Data inserted successfully";
}

?>
``` php code that retrieves the values,
````

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 12:12am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/2 "2023-06-05T00:12:47Z")

</div>

where is the code that submits the form? how do you send the POST, ot should be a form post in the application/x-www-form-urlencoded or so I think not just any body

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:34am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/3 "2023-06-05T00:34:25Z")

</div>

the ardunio prog send the tem and hum values to the php prog to retrieve

```arduino
#include <WiFiNINA.h>
#include <DHT.h>
#include <SPI.h>

IPAddress server(192,168,214,53); // adresse IP du serveur Web
const String http="HTTP/1.1\r\nHost: 192.168.214.53\r\nConnection: close\r\n"; //Modifier l'adresse IP
const String head="GET /sais/addd.php?";

#define DHTPIN 7
#define DHTTYPE DHT22

const char* ssid = "Redmi"; // Replace with your Wi-Fi network name
const char* password = "Hammed2003"; // Replace with your Wi-Fi password

DHT dht(DHTPIN, DHTTYPE);

int h;
float t;
String requete; //Chaîne de caractères pour la requête HTTP GET
boolean etait_connecte = false; // mémorise l'état de la connexion entre deux tours de loop
long derniereRequete = 0; // moment de la dernière requête
char carlu = 0; // pour lire les caractères

WiFiClient client; // L'objet qui nous servira a la communication Ethernet

 void Sending_To_bdd()
{
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.println(requete);
    client.print(requete);
    client.println(http);
    derniereRequete = millis(); // On enregistre le moment d'envoi de la dernière requête
    
    // wait for server response
    while(client.connected() && !client.available()) delay(1);

    String response = "";
    while(client.connected() && client.available()) {
      char c = client.read();
      response += c;
    }
    client.stop();
    
    // extract consigne value from response
    int index = response.indexOf("consigne=");
    if(index != -1) {
      const char consigne = response.substring(index + 9, index + 11).toInt();
      Serial.println(consigne);
          }
    
  } else {
    // 
    Serial.println("connection failed");
    client.stop();
  }
}

 void createRequete(){
  requete = head + "h=" + String(h) + "&t=" + String(t, 1) + " ";
 }

void setup() {
  Serial.begin(9600);
  dht.begin();
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("Wi-Fi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  delay(1000);
}

void loop() {

  // SI on était connecté au tour précédent
  // ET que maintenant on est plus connecté
  // ALORS on ferme la connexion
 if (etait_connecte && !client.connected()) {
    Serial.println();
    Serial.println("Deconnexion !");
    // On ferme le client
    client.stop();
    etait_connecte = client.connected();
  }

  if(!client.connected() && ((millis() - derniereRequete) > 30000)){
    h = dht.readHumidity();
    t = dht.readTemperature();
    createRequete();
    Sending_To_bdd();
    etait_connecte = client.connected();
    Serial.println("Request sent.");
  }
}

```

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 12:36am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/4 "2023-06-05T00:36:10Z")

</div>

> [@olomigeneral](#):
>
> `const String head="GET /sais/addd.php?";`

You are doing GET but expect POST?

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:38am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/5 "2023-06-05T00:38:33Z")

</div>

no i sent the wrong php code, that why i corrected it

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:40am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/6 "2023-06-05T00:40:02Z")

</div>

cause i tried the GET and POST method but it seems like the data are not reaching the server side.  
even tried parsing it through as JSON but no luck

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 12:45am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/7 "2023-06-05T00:45:04Z")

</div>

> [@olomigeneral](#):
>
> not reaching the server side

If you send it on the query string, as long as you can actually connect to the server the parameters should be there. Can you connect to the server and it's just the parameters that are missing? Try echo the entire GET url form php side and see what it looks like

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:54am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/8 "2023-06-05T00:54:07Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/a/b/2/ab2a69ce3b9904f99de35623a913cef30cbb3788.png)

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:54am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/9 "2023-06-05T00:54:50Z")

</div>

the parameters are misssing

---

<div class="post-metadata">

**Author:** ![Idahowalker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/idahowalker/32/238858_2.png) [@Idahowalker](https://forum.arduino.cc/u/Idahowalker)\
**Post date:** [June 5, 2023, 12:55am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/10 "2023-06-05T00:55:22Z")

</div>

Can you manually type the http info and get a positive server result? What do the server error logs indicate as to why the http is being refused?

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:57am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/11 "2023-06-05T00:57:26Z")

</div>

what do you mean?  
localhost/sais/addd.php?h=34&t=22

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 12:57am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/12 "2023-06-05T00:57:35Z")

</div>

> [@olomigeneral](#):
>
> the parameters are misssing

Did you do echo $\_SERVER['QUERY\_STRING'] ( [PHP $\_SERVER (w3schools.com)](https://www.w3schools.com/Php/php_superglobals_server.asp) )

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 12:59am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/13 "2023-06-05T00:59:00Z")

</div>

echo "GET URL: " . $\_SERVER['REQUEST\_URI'];

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 1:02am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/14 "2023-06-05T01:02:02Z")

</div>

Is that supposed to include the query string?

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 1:02am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/15 "2023-06-05T01:02:26Z")

</div>

tried it, but not showing anything

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 1:02am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/16 "2023-06-05T01:02:56Z")

</div>

yep normally, the complete url

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 1:04am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/17 "2023-06-05T01:04:41Z")

</div>

> [@olomigeneral](#):
>
> localhost/sais/addd.php?h=34&t=22

Yes, does that work if you try it from the browser? to see whether its an issue with arduino code or php code

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 1:05am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/18 "2023-06-05T01:05:27Z")

</div>

it works correctly

---

<div class="post-metadata">

**Author:** ![glutio](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/glutio/32/970422_2.png) [@glutio](https://forum.arduino.cc/u/glutio)\
**Post date:** [June 5, 2023, 1:12am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/19 "2023-06-05T01:12:07Z")

</div>

So its something on the Arduino side. And the Serial.println(requete); shows the correct url with query string?

---

<div class="post-metadata">

**Author:** ![olomigeneral](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/olomigeneral/32/961022_2.png) [@olomigeneral](https://forum.arduino.cc/u/olomigeneral)\
**Post date:** [June 5, 2023, 1:13am UTC](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601/20 "2023-06-05T01:13:05Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/6/d/b6d3e8dbfc2159a373c6ce759ce32803945547a1.png)

[Next page](https://forum.arduino.cc/t/http-post-get-problem-probably-the-server/1134601.md?page=2)
