Nodemcu php

Hi everyone
I am using the following code for nodemcu to send data from nodemcu to website (PHP file):

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>

const char* ssid = ""; //not provided here due to privacy but provided in actual code
const char* password = ""; //not provided here due to privacy but provided in actual code

#define button D0

void setup() {

pinMode (button,INPUT);
delay(1000);
Serial.begin(115200);
WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect)
delay(1000);
WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot

WiFi.begin(ssid, password); //Connect to your WiFi router
Serial.println("");

Serial.print("Connecting");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

//If connection successful show IP address in serial monitor
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP()); //IP address assigned to your ESP
}
void loop() {
HTTPClient http; //Declare object of class HTTPClient

String butData, getData, link;
int butvalue=digitalRead(button); //Read Analog value of LDR
butData = String(butvalue); //String to interger conversion

//Post Data
getData = "?state=" + butData ;
link = "http://student-ka-system.000webhostapp.com//index.php" + getData;
http.begin(link.c_str()); //Specify request destination
//Specify content-type header

int httpCode = http.GET(); //Send the request
String payload = http.getString(); //Get the response payload
if (httpCode>0){
Serial.println(getData);
Serial.println(link);
Serial.println(httpCode); //Print HTTP return code
//Print request response payload
Serial.println("done");
}
else{
Serial.println(httpCode);
Serial.println("failed");
}
http.end(); //Close connection

delay(5000); //Post Data at every 5 seconds
}

I am getting the following result on the serial monitor:

13:35:11.726 -> ?state=0
13:35:11.759 -> http://student-ka-system.000webhostapp.com//index.php?state=0
13:35:11.759 -> 200
13:35:11.759 -> done

I am using the following PHP code:

<?php if (!empty($_GET['state'])){ $state= $_GET['state']; echo $state; } else{ echo "no data"; } But the result of the PHP file is no data So please help why am I not getting data on the website? Thanks in advance. [final_done.ino|attachment](upload://rZJBGAFE9TM3dniEYvEnAyiTW1Y.ino) (1.9 KB) ![Capture.PNG|862x374](upload://6uIpsbmm5vvTKcJaSOW4UEvyPbB.png) ![Capture2.PNG|707x219](upload://93vjTGnwdScyrWAH1bhWrWgog3S.png)

@qazi_waleed, please use the code button </> when posting code.

Images so we don't have to download them. See this Simple Image Posting Guide

...R

PS ... please don't post pictures of text - just copy and paste the text

@qazi_waleed

TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

In PHP the empty() function returns FALSE if the variable's value is "0". Meaning empty("0") will return false. That's why your if is not executed when your state is "0".
From the PHP manual:

The following values are considered to be empty:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)

In order to check if a variable is set in PHP use the isset() function.

So your PHP code should be:

<?php

 if (isset($_GET['state'])){
    $state= $_GET['state'];
    echo $state;
   }
 else{
     echo "no data";
 }