HTTP POST GET problem probably the server

shit.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

<?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,

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

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

#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.");
  }
}

You are doing GET but expect POST?

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

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

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

image

the parameters are misssing

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?

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

Did you do echo $_SERVER['QUERY_STRING'] ( PHP $_SERVER (w3schools.com) )

echo "GET URL: " . $_SERVER['REQUEST_URI'];

Is that supposed to include the query string?

tried it, but not showing anything

yep normally, the complete url

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

it works correctly

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

image