I need help for sending sensor data to mysql online host

Hello, I need help. I am making such a web-based temperature and humidity monitoring application. The device that I use is DHT22, Arduino, and Ethernet shield for internet connection from the router. The scenario of my project where the sensor data will be sent to mysql webhost (I use 000webhost.com for hosting). To input data from Arduino to MySQL using PHP with the Get method.
From the experiments carried out on the arduino serial output it can connect to the web server, but the data doesn't go to mysql. Before I tried it with localhost (xampp) data from the sensor can enter mysql localhost. Please help me so that sensor data can be saved to mysql (webhost).

This my arduino code :

#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"

byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
//byte ip[] = {192, 168, 1, 105 }; //Enter the IP of ethernet shield

char server[] = "www.rizkiprat070.000webhostapp.com"; //alamat hosting rizkiprat070.000webhostapp.com www.nyankosensei.pe.hu
EthernetClient client;

#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");  //DHCP
  //  Ethernet.begin(mac, ip); //static IP (uncommend ipaddress)
  }
  dht.begin(); 
  delay(1000); // GIVE THE SENSOR SOME TIME TO START
  
//delay(1000);
  Serial.println("connecting...");
}

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

if (client.connect(server, 80)) { //localhost : IP 192.168.1.103
Serial.println("connected");
client.print("GET /data1.php?"); 
client.print("temperature=");
client.print(temp);
client.print("&humidity=");
client.println(hum);
client.println("HTTP/1.1");
client.println("Host: www.rizkiprat070.000webhostapp.com");
client.print("Content-Type: application/x-www-form-urlencoded");
client.println("Connection: close");
client.println();
Serial.print("Temperature= ");
Serial.println(temp);
Serial.print("Humidity= ");
Serial.println(hum);
client.stop(); //Closing the connection
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
delay(10000);
}

PHP code for connection to database (connection.php):

<?php
$username = "id6857137_user";
$pass = "r123456";
$host = "localhost";
$db_name = "id6857137_jajal";
$con = mysqli_connect ($host, $username, $pass);
if($con=== FALSE) { 
die(mysqli_connect_error($con)); 
}
$db = mysqli_select_db ($con, $db_name );
?>

PHP code for insert data to database (data1.php):

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

Should this line:

$host = "localhost";

be

$host = "www.rizkiprat070.000webhostapp.com";

?

Have a look at my code here for other ideas.

If you have doubts about your php/mySql/webserver configuration you can usually (if you are using the GET method) test with a normal web browser to simulate what the Arduino would be doing, for example:

http://www.rizkiprat070.000webhostapp.com/data.php?temperature=25&humidity=50

Warning Temperature may not be the same as temperature

PaulRB:

$host = "www.rizkiprat070.000webhostapp.com";

thank you, but for the hostname, I think it's correct, because I tried to enter the manual through the web browser, the data can be entered into mysql.

6v6gt:
If you have doubts about your php/mySql/webserver configuration you can usually (if you are using the GET method) test with a normal web browser to simulate what the Arduino would be doing, for example:

http://www.rizkiprat070.000webhostapp.com/data.php?temperature=25&humidity=50

Warning Temperature may not be the same as temperature

I have tried it, with "rizkiprat070.000webhostapp.com/data1.php?temperature=30&humidity=20" and the data can enter the database

rpm070:
thank you, but for the hostname, I think it's correct, because I tried to enter the manual through the web browser, the data can be entered into mysql.

I do not think you understand my suggestion from post #1. I am suggesting you change connection.php.

PaulRB:
I do not think you understand my suggestion from post #1. I am suggesting you change connection.php.

yes, I understand what you mean, if I change host (on connection.php) to rizkiprat070.000webhostapp.com, PHP can't connect to mysql.

rpm070:
yes, I understand what you mean, if I change host (on connection.php) to rizkiprat070.000webhostapp.com, PHP can't connect to mysql.

Now that I think about it, both values of hostname in connection.php should work (assuming the database is hosted on the same system as the web server, which they usually are). So I don't know why my suggestion would stop it from working.

But the fact that you can insert data to the database from browser as suggested means that the problem must be in your Arduino code, I think. Can you post output you see on serial monitor? I suggest you copy every Client.print/ln() line and change the copied lines to Serial.print/ln() so you can see exactly what is being sent to the client.

PaulRB:
Now that I think about it, both values of hostname in connection.php should work (assuming the database is hosted on the same system as the web server, which they usually are). So I don't know why my suggestion would stop it from working.

But the fact that you can insert data to the database from browser as suggested means that the problem must be in your Arduino code, I think. Can you post output you see on serial monitor? I suggest you copy every Client.print/ln() line and change the copied lines to Serial.print/ln() so you can see exactly what is being sent to the client.

what do you think about my arduino program, if you think there is a mistake please let me know. thank you

You need a space before the HTTP word:

client.println("HTTP/1.1");

Check an example web client get statement very carefully to see if you have made other similar errors.

I though about that missing space also. But it is separated from the humidity value by a new line:

client.println(hum);
client.println("HTTP/1.1");

so I thought that was ok (the new line counts as whitespace). But maybe the HTTP/1.1 must be on the same line as the GET. Worth trying:

client.print(hum);
client.println(" HTTP/1.1");

PaulRB:
I though about that missing space also. But it is separated from the humidity value by a new line:

client.println(hum);

client.println("HTTP/1.1");



so I thought that was ok (the new line counts as whitespace). But maybe the HTTP/1.1 must be on the *same line* as the GET. Worth trying

Ah yes. I didn't notice the line feed before, which is almost certainly wrong as well.
The user has to find a known valid example and follow it very carefully with attention to that sort of detail.
Sometimes, looking in the Apache access log files also helps to show up such errors.

PaulRB:
I though about that missing space also. But it is separated from the humidity value by a new line:

client.println(hum);

client.println("HTTP/1.1");



so I thought that was ok (the new line counts as whitespace). But maybe the HTTP/1.1 must be on the *same line* as the GET. Worth trying:



client.print(hum);
client.println(" HTTP/1.1");

6v6gt:
Ah yes. I didn't notice the line feed before, which is almost certainly wrong as well.
The user has to find a known valid example and follow it very carefully with attention to that sort of detail.
Sometimes, looking in the Apache access log files also helps to show up such errors.

Thank you @PaulRB & @6v6gt my program was successful. thanks

I thought about starting a new post but i found this. I have the excact same issue and i think i´ve tried about everything please help me.

"I thought about starting a new post"

That would probably be a good thing to do so your issues have a separate discussion.

Deppi:
I have the excact same issue and i think i´ve tried about everything

If the fix in this topic did not correct your problem, perhaps it is not the exact same issue?