data is not saving in Mysql from ardunio

hi all
i`m using nodemcu v1.0… is connecting to data base but the output in mysql is zero
please help

#include <ESP8266WiFi.h>

const char* ssid     = "****";
const char* password = "****";
const char* host = "192.168.0.112";

void setup()
{
  Serial.begin(115200);
  delay(10);

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop() {
  int sensor = analogRead(A0);
  //String sensor = String(sensor);

    WiFiClient client; 
  if (client.connect(host, 80)) {

    client.print( "GET /connect.php?");
    client.print("sensor=");;
    client.print(sensor);
    Serial.print(sensor);
    client.println( "HTTP/1.1");
    client.println( "Connection: close" );
    client.stop();
    Serial.println("CONNECTED");
  }
    else {
    Serial.println("–> connection failed/n");
  }
  delay(50000);
}
<?php 
$servername = "localhost"; 
$username = "root";  
$password = "";

$sensor = $_GET["sensor"]; 
$conn = mysql_connect($servername, $username, $password);
if ($conn) {
    echo "Connected successfully";
} 
else {
    echo "connection failed";
}

$conndb = mysql_select_db('coe', $conn);

echo  "
";

$sql_insert ="insert into pulses (sensor) values ('$sensor')";
mysql_query($sql_insert);
if($sql_insert){
    echo "insert successfull";
}
else {
    echo "insert failed";
}

?>

    client.print( "GET /connect.php?");
    client.print("sensor=");;
    client.print(sensor);
    Serial.print(sensor);
    client.println( "HTTP/1.1");

If your sensor value is 27, your GET request looks like GET /connect.php?sensor=27HTTP/1.1". Not exactly a valid GET request, is it?

I'm pretty sure that the PHP script can not store 27HTTP/1.1 in your database.

You could echo more data in the script, and you could look at the logs on your server to see what requests are being made.

but why i cannot get sensor value ?

You MUST have a space between the sensor value and the HTTP portion of the request.

    client.print( "GET /connect.php? ");
    client.print("sensor=");;
    client.print( sensor);

    client.println( " HTTP/1.1");
     client.println(" Host: 192.168.0.112");
    client.println( " Connection: close" );

Like this?
please help and sorry for disturbance

Like this?

No. The complete GET request should be “GET /connect.php?sensor=xxxx HTTP/1.1”. Look at where the spaces are.

    client.print("GET /connect.php?sensor=");
    client.print(sensor);
    client.println(" HTTP/1.1");

i try this but without success :( :( :( :(

istabraq: i try this but without success :( :( :( :(

So, what do your server logs tell you? What server software are you running? Apache?

here is my Apache software log :

192.168.0.183 - - [05/Dec/2016:15:54:24 +0300] "GET /connect.php?sensor=516 HTTP/1.1" 400 226 192.168.0.183 - - [05/Dec/2016:15:55:15 +0300] "GET /connect.php?sensor=508 HTTP/1.1" 400 226 192.168.0.183 - - [05/Dec/2016:15:56:05 +0300] "GET /connect.php?sensor=490 HTTP/1.1" 400 226 192.168.0.183 - - [05/Dec/2016:15:56:56 +0300] "GET /connect.php?sensor=494 HTTP/1.1" 400 226

192.168.0.183 this is my nodemcu ip address

PaulS: So, what do your server logs tell you? What server software are you running? Apache?

how to request http ?

are these corrects ?

http://localhost//connect.php?sensor=sensor HTTP/1.1 or http://localhost//connect.php?sensor=sensor or http://localhost//connect.php?sensor=546 HTTP/1.1 or http://localhost//connect.php?sensor=546 or http://localhost//connect.php?sensor=

please help :(

192.168.0.183 - - [05/Dec/2016:15:54:24 +0300] "GET /connect.php?sensor=516 HTTP/1.1" 400 226

Do you know what the fields mean? The first is the IP address that the request came from. The date is fairly obvious. The request is fairly obvious. The next field is the return code that the server sent. Do you know what a 400 return code means?

400 is a bad request. Perhaps the issue is that your server is not supporting the version 1.1 HTTP protocol. Try the request using HTTP/1.0.

oh Thanks

but the same issue
what you say if i install database in Ubuntu desktop may i face less issues?
Thanks a lot

istabraq: oh Thanks

but the same issue what you say if i install database in Ubuntu desktop may i face less issues? Thanks a lot

No, I don't think that changing operating systems is going to help.

    client.println( "HTTP/1.1");
    client.println( "Connection: close" );
    client.stop();
    Serial.println("CONNECTED");

You make a GET request, to execute some script on some server. Then, you tell the server to f**k off, instead of actually reading what the server had to say. Perhaps in the data that you are not reading, there is a clue-by-four waiting to whack you upside the head.