arduino + ethernet shield + dht22 AND apache + php + mysql

Hi, I am capturing humidity and temperature with the dht22 sensor, I managed to display them on the serial monitor that has the arduino platform, but when I try to send this data to another PC that serves as the server in which Xammp runs, Connection message set but can not store the data in Mysql, I do not know what my error. Please help me by taking the trouble to check my code, and tell me that I am wrong thanks for your time.

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

#define DHTPIN 2                
#define DHTTYPE DHT22      

DHT dht(DHTPIN, DHTTYPE);                   

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x4E, 0xD7 };      
byte ip[] = { 192,168,1,87 };                             
byte server[] = { 192,168,1,117 };                        
EthernetClient client;

void setup() {
  Ethernet.begin(mac, ip); 

  Serial.print("address IP: ");
  Serial.print("run Sensor DHT");

void loop() {
  float h = dht.readHumidity(); 
  float t = dht.readTemperature();  
  if (isnan(h) || isnan(t)) {
    Serial.println("Wrong sensor DHT!");
  Serial.print("Humidity: "); 
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.println(" *C ");

  if (client.connect(server, 80)) {  
    client.print("GET /test/iot.php?valorh="); 
    client.print("GET /test/iot.php?valort="); 
    client.println(" HTTP/1.0");
    client.println("User-Agent: Arduino 1.0");
  } else {
    Serial.println("Wrong conexion");
  if (!client.connected()) {

I have a folder on my server called test and inside these two files config.php and iot.php. The config.php file contains the information to establish a connection to the database. The iot.php file uploads the received data to the sensor database.


// config.php
    $dbhost = "localhost";
    $dbuser = "root";
    $dbpass = "";
    $dbname = "sensores";
    $con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);


    // iot.php
    $valorh = mysqli_real_escape_string($con, $_GET['valorh']);
    $query = "INSERT INTO valores(valorh) VALUES('".$valorh."')";
    $valort = mysqli_real_escape_string($con, $_GET['valort']);
    $query = "INSERT INTO valores(valort) VALUES('".$valort."')";
    mysqli_query($con, $query);

Also in Mysql I have created the database sensores, inside I have the table valores:

thx for helping me.

You can check your PHP code by visiting the iot.php URL in your browser with values in the query string something like


Rather than do two seperate GETs you can combine them like I did above… try something like

    client.print("GET /test/iot.php?valorh=");
    client.println("Host:");  // change this to your IP address
    client.println("Connection: close");

And find the location of the XAMPP log files so you can monitor whats being sent from the arduino.

Rather than do two seperate GETs you can combine them like I did above

You can do two separate GET requests, but each one must be completely separate. Make one, read the response, and then make the second one.

What is being sent, by your code, to the server is something like:
“GET /test/iot.php?valorh=33 GET /test/iot.php?valort=14 HTTP/1.0”
which is NOT a valid GET request.