LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Embedded & Single-board computer (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/)
-   -   data is not saving in Mysql from ardunio (https://www.linuxquestions.org/questions/linux-embedded-and-single-board-computer-78/data-is-not-saving-in-mysql-from-ardunio-4175594760/)

istabraq 12-04-2016 06:16 AM

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

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";
}

?>


norobro 12-04-2016 01:03 PM

PHP Code:

mysql_query($sql_insert); 
if(
$sql_insert){
    echo 
"insert successfull";
}
else {
    echo 
"insert failed";


You're testing the string $sql_insert when you need to be testing the result of the query.
Try something like this:
PHP Code:

$result mysql_query($sql_insert);
if(
$result){
    echo 
"insert successfull";
}
else {
    echo 
"insert failed " mysql_error($conn);



istabraq 12-05-2016 06:54 AM

thanks but i try this but i get insert successful :(


All times are GMT -5. The time now is 04:38 PM.