hi all
i`m using nodemcu v1.0.. is connecting to data base but the output in mysql is zero
please help
Code:
#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 Code:
<?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 "<br>";
$sql_insert ="insert into pulses (sensor) values ('$sensor')";
mysql_query($sql_insert);
if($sql_insert){
echo "insert successfull";
}
else {
echo "insert failed";
}
?>