LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 12-04-2016, 06:16 AM   #1
istabraq
LQ Newbie
 
Registered: Nov 2016
Posts: 11

Rep: Reputation: Disabled
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";
}

?>
 
Old 12-04-2016, 01:03 PM   #2
norobro
Member
 
Registered: Feb 2006
Distribution: Debian Sid
Posts: 792

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
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);

 
Old 12-05-2016, 06:54 AM   #3
istabraq
LQ Newbie
 
Registered: Nov 2016
Posts: 11

Original Poster
Rep: Reputation: Disabled
thanks but i try this but i get insert successful
 
  


Reply

Tags
arduino, mysql, php, wifi


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: 5 favorite Raspberry Pi and Ardunio projects LXer Syndicated Linux News 0 01-19-2015 05:54 PM
[SOLVED] Saving data after windows failure ... mind_exploit Linux - Hardware 7 04-17-2013 06:36 PM
LXer: Saving Yourself with Data Replication LXer Syndicated Linux News 0 10-20-2010 04:20 AM
Saving Data and Documents on Another partition by Default ashwanisinha Linux - Newbie 2 09-08-2007 01:24 PM
saving data on a floppy jamaso Linux - General 5 03-12-2002 11:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 06:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration