not able to update database from arduino calling php page that inserts to db

I am using the below web client sketch that connects to server 192.168.1.3

#include <SFE_BMP180.h>
#include <SPI.h>
#include <Ethernet.h>
#include<dht.h>
dht DHT;

// You will need to create an SFE_BMP180 object, here called "pressure":
SFE_BMP180 bmp;

#define DHT11_PIN 8

double tempInC;
int humidity;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000; //READING INTERVAL

String data;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; //wait for serial port to connect. Needed for native USB port only
  }

  if (bmp.begin()) {
    Serial.println("BMP init Success");
  }

  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    client.println("GET /arduino/add.php?temp1=31.32&&hum1=16 HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    client.print("Content-Length: ");
    client.println(data.length());
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");
  data = "";
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  char status;
  status = bmp.startTemperature();
  // tempInC = DHT.temperature;
  if (status != 0) {
    delay(status);
    status = bmp.getTemperature(tempInC);
  }
  else Serial.println("error retrieving temperature measurement\n");

  humidity = DHT.humidity;
  data = "?temp1=" + String(tempInC) + "&&hum1=" + String(humidity);

  if (client.connect(server, 80)) {
    Serial.print(F("connected. My IP is "));
    Serial.println(Ethernet.localIP());
    // Make a HTTP request:
    client.print("GET /arduino/add.php");
    client.print(data);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    //   client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.println(data.length());
  }
  else {
    Serial.println("connection failed");
  }
  Serial.println(data);
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  if (client.connected()) {
    client.stop();	// DISCONNECT FROM THE SERVER
  }
  //  delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
  delay(20000);
}

I am not sure what is wrong with the code above , it just doesnt inserts into database however if I directly executes the 192.168.1.3/arduino/add.php?temp1=31.32&&hum1=16

then it works.

<?php
        include("connect.php");
        
        $link=Connection();

        $temp1=$_GET["temp1"];
        $hum1=$_GET["hum1"];

        $query = "INSERT INTO `tempLog` (`temperature`, `humidity`) 
                VALUES ('".$temp1."','".$hum1."')"; 
        
        mysql_query($query,$link);
        mysql_close($link);

        header("Location: index.php");
?>

which makes me think that PHP SQL part is correct some not right with my arduino sketch,

Can anyone of you guys please help.

  data = "?temp1=" + String(tempInC) + "[color=red]&&[/color]hum1=" + String(humidity);

why && ?

This is not a well formed GET request

 client.print("GET /arduino/add.php");
    client.print(data);
    client.println(" HTTP/1.1");
    client.print("Host: ");
    client.println(server);
    //   client.println("Content-Type: application/x-www-form-urlencoded");
    client.print("Content-Length: ");
    client.println(data.length());

try with

client.print("GET /arduino/add.php");
client.print(data);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();  // <-- important empty line

also why do you use the String class?
  data = "?temp1=" + String(tempInC) + "&&hum1=" + String(humidity); is not necessary.

you’ll use way more memory than really required…

Suggest you go for this

client.print(F("GET /arduino/add.php?temp1="));
client.print(tempInC);
client.print(F("&hum1="));
client.print(humidity);
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(server);
client.println(F("Connection: close"));
client.println();  // <-- important empty line
        $temp1=$_GET["temp1"];
        $hum1=$_GET["hum1"];

You have created a name=value pair for the names temp1 and &hum1, not temp1 and hum1.

Now I am using the updated code:

 if (client.connect(server, 80)) {

    // Make a HTTP request:
    client.print(F("GET /arduino/add.php?temp1="));
    client.print(tempInC);
    client.print(F("&hum1="));
    client.print(humidity);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();

  }
  else {
    Serial.println(F("connection failed"));
  }

but still it doesnt work, I have not changed the add.php, as I understand as per the above logic it will stay same.

I also don’t seem to have any firewall see attached screenshot.

However my web server has HTTP to HTTPS redirection , can that cause problem ?

Are you seeing "connection failed" in the console?

is your web server receiving a request? (check the logs)

J-M-L:
Are you seeing "connection failed" in the console?

no

J-M-L:
is your web server receiving a request? (check the logs)

I do not know how/ where to check that ;(

what is your web server? how is it configured?

J-M-L:
what is your web server? how is it configured?

Its Raspberry Pi , self hosted .

here is the configuration of default enabled site:

<VirtualHost *:80>
      RewriteEngine on
      ServerName     192.168.1.3
      # force ssl
      RewriteCond     %{SERVER_PORT} ^80$
      RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>


<VirtualHost *:443>
      ServerAdmin pydio@localhost.localdomain.com
      ServerName 192.168.1.3
      SSLEngine on
      SSLProtocol ALL -SSLv2 -SSLv3
      SSLHonorCipherOrder On
      SSLVerifyDepth 10
      SSLCertificateFile /etc/ssl/localcerts/raspberrypi.local.crt
      SSLCertificateKeyFile /etc/ssl/localcerts/raspberrypi.local.key
      DocumentRoot /var/www/php
      ErrorLog ${APACHE_LOG_DIR}/pydio-error.log
      CustomLog ${APACHE_LOG_DIR}/pydio-access.log combined
      <Directory /var/www/php/>
      AllowOverride All
      </Directory>
</VirtualHost>

post full code please

Here is the full code of arduino sketch:

#include <SFE_BMP180.h>
#include <SPI.h>
#include <Ethernet.h>
#include<dht.h>
dht DHT;

// You will need to create an SFE_BMP180 object, here called "bmp":
SFE_BMP180 bmp;

#define DHT11_PIN 8

double tempInC;
int humidity;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 177);

EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to

long previousMillis = 0;
unsigned long currentMillis = 0;
long interval = 250000; //READING INTERVAL

String data;

void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; //wait for serial port to connect. Needed for native USB port only
  }

  if (bmp.begin()) {
    Serial.println("BMP init Success");
  }

  // start the Ethernet connection:
  Ethernet.begin(mac, ip);
  Serial.print(F("connected. My IP is "));
  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);
  data = "";
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  char status;
  status = bmp.startTemperature();
  // tempInC = DHT.temperature;
  if (status != 0) {
    delay(status);
    status = bmp.getTemperature(tempInC);
  }
  else Serial.println("error retrieving temperature measurement\n");

  humidity = DHT.humidity;

  if (client.connect(server, 80)) {

    // Make a HTTP request:
    client.print(F("GET /arduino/add.php?temp1="));
    client.print(tempInC);
    client.print(F("&hum1="));
    client.print(humidity);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();

  }
  else {
    Serial.println(F("connection failed"));
  }
//  Serial.print("Temp: ");
//  Serial.print(tempInC);
//  Serial.print(" Humidity: ");
//  Serial.println(humidity);
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  else{
    Serial.println("Client not available");
  }
  if (client.connected()) {
    client.stop();	// DISCONNECT FROM THE SERVER
  }
  //  delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
  delay(10000);
}

Why delay(status); ?

Not sure about the library you use but shouldn’t you have something like

    float temperature;
    bmp.getTemperature(&temperature); // <-- Need the address

J-M-L:
Why delay(status); ?

Not sure about the library you use but shouldn’t you have something like

    float temperature;

bmp.getTemperature(&temperature); // ← Need the address

Hi J-M-L,
Sorry for late reply I only get time to work on this on weekends, I got rid of the bmp stuff and only using DHT11 of testing,
Surprising another problem has popped up, and my ethernet shield is not able to work as client most of the time it will assign itself IP 255.255.255.255 , I don’t know why . I am extremely upset .
Here is the updated sketch:

#include "Ethernet.h"
#include <SPI.h>
#include<dht.h>
dht DHT;
#define DHT11_PIN 8
double tempInC;
int humidity;
byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
//IPAddress ip(192, 168, 1, 177);
//char server[] = "www.google.com";    // name address for Google (using DNS)
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,177);
byte subnet[] = { 255, 255, 255, 0 }; //assigning subnet mask
byte gateway[] = { 192, 168, 1, 1 }; //assigning gateway
EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to
String data;
void setup() {
  Serial.begin(9600);
  while (!Serial) {
    ; //wait for serial port to connect. Needed for native USB port only
  }
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.print(F("connected. My IP is "));
  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);
  data = "";
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  delay(200);
  tempInC = DHT.temperature;
  humidity = DHT.humidity;
  Serial.print("Temp: ");
  Serial.print(tempInC);
  Serial.print(" Humidity: ");
  Serial.println(humidity);
  if (client.connect(server, 80)) {
    // Make a HTTP request:
    client.print(F("GET /arduino/add.php?temp1="));
    client.print(tempInC);
    client.print(F("&hum1="));
    client.print(humidity);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();
  }
  else {
    Serial.println(F("connection failed"));
  }
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  else {
    Serial.println("Client not available");
  }
  if (client.connected()) {
    client.stop();	// DISCONNECT FROM THE SERVER
  }
  //  delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
  delay(10000);
}

this is the output I am getting

connected. My IP is 255.255.255.255
Temp: 26.00 Humidity: 63
connection failed
Client not available

I dont know what to do, I had plans for future to make graph out of data but I am not able to move on from this step.

I removed SD card and changed server port

if (client.connect(server, 80)) {

to

if (client.connect(server, 443)) {

and it connects.
but the below code doesn't seems to push data to database

//Make a HTTP request
client.print(F("GET /arduino/add.php?temp1="));
client.print(tempInC);
client.print(F("&hum1="));
client.print(humidity);
client.println(F(" HTTP/1.1"));
client.print(F("Host: "));
client.println(server);
client.println(F("Connection: close"));
client.println();

What's your chip select pin for the SD? you need to handle that correctly. Why don't you use DHCP?

but the below code doesn't seems to push data to database

The code doesn't even compile, so any expectation that it will push data to a database is completely unrealistic. POST ALL OF YOUR CODE DOES apply to you!