Arduino ethernet shield can't send dht22 data to mysql base

I am trying to write DHT22 temperature and humidity data to a database using Arduino Ethernet Shield and Arduino UNO as in this example: Logging Data to Database Using Arduino Ethernet Shield - Arduino Project Hub. My problem is that data is passed to the serial monitor, but not passed to the database.

Arduino sketch:

    #include <SPI.h>
    #include <Ethernet.h>
    #include "DHT.h"
    #define DHTPIN 7
    #define DHTTYPE DHT22
    DHT dht(DHTPIN, DHTTYPE);
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    byte ip[] = { 192, 168, 3, 2 }; //Enter the IP of ethernet shield
    byte dns[] = { 192, 168, 0, 2 };
    byte gateway[] = { 192, 168, 0, 1 };
    byte subnet[] = { 255, 255, 248, 0 };
    byte serv[] = { 192, 168, 7, 1 }; //Enter the IPv4 address
    EthernetClient cliente;
    void setup() {
    Serial.begin(9600); //setting the baud rate at 9600
    Ethernet.begin(mac, ip, dns, gateway, subnet);
    dht.begin();
    }
    void loop() {
    float hum = dht.readHumidity(); //Reading the humidity and storing in hum
    float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
    float fah = dht.readTemperature(true); //reading the temperature in Fahrenheit
    float heat_index = dht.computeHeatIndex(fah, hum); //Reading the heat index in Fahrenheit
    float heat_indexC = dht.convertFtoC(heat_index); //Converting the heat index in Celsius
     if (cliente.connect(serv, 80)) { //Connecting at the IP address and port we saved before
    Serial.println("connected");
    cliente.print("GET /arduino-test/data.php?"); //Connecting and Sending values to database
    cliente.print("temperature=");
    cliente.print(temp);
    cliente.print("&humidity=");
    cliente.print(hum);
    cliente.print("&heat_index=");
    cliente.println(heat_indexC);
    //Printing the values on the serial monitor
    Serial.print("GET arduino-test/data.php?");
    Serial.print("temperature=");
    Serial.print(temp);
    Serial.print("&humidity=");
    Serial.print(hum);
    Serial.print("&heat_index=");
    Serial.println(heat_indexC);
    cliente.stop(); //Closing the connection
    }
    else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    }
    delay(5000);
    }

data.php

<?php
include ('connection.php');
$sql_insert = "INSERT INTO arduino_test (temperature, humidity, heat_index) VALUES ('".$_GET['temperature']."', '".$_GET['humidity']."', '".$_GET['heat_index']."')";
if(mysqli_query($con,$sql_insert))
{
echo "Done";
mysqli_close($con);
}
else
{
echo "error is ".mysqli_error($con );
}
?>

What's the problem? Thanks in advance.

Please show your mysql table.
And also, please test the DHT sensor value by using Serial.println() first. If you use the DHT library from Adafruit, you can use the below code to check whether reading from sensor is failed or not.

  // check if any reads failed
  if (isnan(humi) || isnan(tempC) || isnan(tempF)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humi);
    Serial.print("%");

    Serial.print("  |  "); 

    Serial.print("Temperature: ");
    Serial.print(tempC);
    Serial.print("°C ~ ");
    Serial.print(tempF);
    Serial.println("°F");
  }

You can get full code from this DHT tutorial

I tested the DHT sensor. its works. I attach image with look of my mysql table.

serial monitor.PNG

serial monitor.PNG

Test your API from web browser: http://192.168.3.2/arduino-test/data.php?temperature=40&humidity=29.3&heat_index=5

I tested: http://arduino-test/data.php?temperature=1&humidity=1&heat_index=1. It's insert data into mysql table.

Try: before: client.stop(); , read the response the data from server.

while(client.available())
{
  // read an incoming byte from the server and print them to serial monitor:
  char c = client.read();
  Serial.print(c);
}

if(!client.connected())
{
  // if the server's disconnected, stop the client:
  Serial.println("disconnected");
  client.stop(); 
}

See detail in Arduino HTTP request

a) please show the serial output of your sketch in the opening post
b) try the simple Web client example from the IDE connecting to google (like in the example). Does it work?
c) if yes: adopt the IDE Web client example to the IP of your server. Do you get an response? Show the Serial Output.
d) if yes: adopt the IDE Web client example to pass some dummy values. Does it work? Show the Serial Output.

Please describe exactly what happens on your side.
Show the last working code and the first non working code that didn't work like expected.

Hi, noiasca:
a) Serial output of my sketch:

connection failed
connected
GET arduino-test/data.php?temperature=24.70&humidity=32.10&heat_index=24.06
connected
GET arduino-test/data.php?temperature=24.80&humidity=32.20&heat_index=24.18

b) Web client example. In my serial monitor i got:

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.3.2
connecting to www.google.com...
connected to 173.194.73.104
HTTP/1.1 200 OK
Content-Type: text/html; charset=ISO-8859-1
Date: Wed, 23 Dec 2020 08:38:09 GMT
Expires: -1
Cache-Control: private, max-age=0
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2020-12-23-08; expires=Fri, 22-Jan-2021 08:38:09 GMT; path=/; domain=.google.com; Secure
Set-Cookie: CGIC=; expires=Mon, 21-Jun-2021 08:38:09 GMT; path=/complete/search; domain=.google.com; HttpOnly
Set-Cookie: CGIC=; expires=Mon, 21-Jun-2021 08:38:09 GMT; path=/search; domain=.google.com; HttpOnly
Set-Cookie: NID=205=dcQw1iLdbJZz0OSOFLnMw7-LZ4tGljMm9rVuQ-8NNPD1JJEUGIV3x5tF7Rfsu0aBCVumlVUI2LriA9lTEGt5ggmlgATq538rP5YEVFHKqDr3kTq4_DiMJBIGtSXLGo4XHgr4EEOk6hYEXPbjfcRK_Q-GHBIHWTWPXZl6mO_ZlmM; expires=Thu, 24-Jun-2021 08:38:09 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
...

c) Do I need to change IPAddress server(74,125,232,128); to IPAddress server(192,168,7,1); ?

c) Do I need to change IPAddress server(74,125,232,128); to IPAddress server(192,168,7,1); ?

yes, because you want to reach that address.
a and b were to prove whether the hardware/LAN Setup is basically working.

be careful, you have also to modify (or delete) the HOST in row 90.

I changed server IP and host to IPAddress server(192,168,7,1) and client.println("Host: 192.168.7.1"). Looks like it can't connect to my server.

serial.PNG

serial.PNG

The response show that you connected successfully to Web Server. However, URL not found. Please check your URL and Change below line in your code
cliente.print("GET /arduino-test/data.php?"); //Connecting and Sending values to database

the server responses with a nice HTTP 404 --> you are accessing a resource which is not available on your server. All that additional information comes from your server. partly success!

now adopt line 89 but attention, the original web client uses a client object called "client"

    client.println("GET /data.php?temperature=1&humidity=2&heat_index=5 HTTP/1.0");

if it doesn't work - post your code and your serial output.

p.s. If you post serial output - please post it also as text in code tags. you don't need to make a picture.

It works on web client example, data pass to data base.

Initialize Ethernet with DHCP:
Failed to configure Ethernet using DHCP
connecting to 192.168.7.1...
connected to 192.168.7.1
HTTP/1.1 200 OK
Date: Wed, 23 Dec 2020 12:15:46 GMT
Server: Apache
Content-Length: 4
Connection: close
Content-Type: text/html; charset=UTF-8

Done
disconnecting.
Received 154 bytes in 1.0224, rate = 0.15 kbytes/second

data.PNG

But when i try this line in my sketch it's not working. Data is not pass.

data.PNG

You have a working client based on the IDE example.
Now, implement the DHT sensor into this working example.

I solved it. my final code looks like this:

#include <SPI.h>
    #include <Ethernet.h>
    #include "DHT.h"
    #define DHTPIN 7
    #define DHTTYPE DHT22
    DHT dht(DHTPIN, DHTTYPE);
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Newer Ethernet shields have a MAC address printed on a sticker on the shield
    IPAddress server(192, 168, 7, 1); //IPv4 address
    // Set the static IP address to use if the DHCP fails to assign
    IPAddress ip(192, 168, 0, 177);
    IPAddress myDns(192, 168, 0, 1);
    
    EthernetClient client;
    void setup() {
    Serial.begin(9600); //setting the baud rate at 9600
    Ethernet.begin(mac);
    //Ethernet.begin(mac, ip, myDns);
    dht.begin();
    }
    void loop() {
    float hum = dht.readHumidity(); //Reading the humidity and storing in hum
    float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
    float fah = dht.readTemperature(true); //reading the temperature in Fahrenheit
    float heat_index = dht.computeHeatIndex(fah, hum); //Reading the heat index in Fahrenheit
    float heat_indexC = dht.convertFtoC(heat_index); //Converting the heat index in Celsius
    
     if (client.connect(server, 80)) { //Connecting at the IP address and port we saved before
    Serial.println("connected");
    client.print("GET /data.php?");
    client.print("temperature=");
    client.print(temp);
    client.print("&humidity=");
    client.print(hum);
    client.print("&heat_index=");
    client.print(heat_indexC);
    client.println(" HTTP/1.1");
    client.println("Host: 192.168.7.1");
    client.println("Connection: close");
    client.println();
    
    Serial.print("GET /data.php?");
    Serial.print("temperature=");
    Serial.print(temp);
    Serial.print("&humidity=");
    Serial.print(hum);
    Serial.print("&heat_index=");
    Serial.print(heat_indexC);
    Serial.println(" HTTP/1.1");
    
    client.stop(); //Closing the connection
    } else {
    //if you didn't get a connection to the server:
    Serial.println("connection failed");
    }
    delay(10000);
    }