I'm only getting to Post data to one column "Vrms" which is 899, "Irms" column just shows the value '0'
<?php
foreach ($_REQUEST as $key => $value)
{
if ($key ==="Vrms") {
$yourdata = $value;
}
if ($key ==="Irms") {
$yourdata2 = $value;
}
}
//
// EDIT: Your mysql database account
information
//
$username="root";
$password="password";
$database="test";
$tablename = "test12";
$localhost="localhost";
// Check Connection to Database
if (mysql_connect($localhost, $username,
$password))
{
@mysql_select_db($database) or die
("Unable to select database");
// Next two lines will write into your
table 'test_table_name_here' with 'yourdata'
value from the arduino and will timestamp that
data using 'now()'
$query = "INSERT INTO `test`.`test12`
(`Vrms`, `Irms`, `timestamp`) VALUES
('$yourdata', '$yourdata2',
CURRENT_TIMESTAMP)";
$result = mysql_query($query);
} else {
echo('Unable to connect to
database.');
}
?>
#include <SPI.h>
#include <WiFi.h>
//
// EDIT: change the SSID and password to match
your network
//
char ssid[] = "Username"; // your network
SSID (name)
char pass[] = "password"; // your
network password
int status = WL_IDLE_STATUS;
WiFiClient client;
//
// EDIT: server address to match your domain
//
char server[] = "www.yourdomain.com";
// this is the data that will be passed into
your POST and matches your mysql column
int yourarduinodata2 = 899;
String y = "Vrms=";
String yourdata;
int yourarduinodata = 999;
String x = "Irms=";
String yourdata2;
void setup() {
Serial.begin(9600);
// attempt to connect to wifi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to
SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection
delay(10000);
}
// you're connected now, so print out the
status
printWifiStatus();
// Combine yourdatacolumn header (yourdata=)
with the data recorded from your arduino
// (yourarduinodata) and package them into
the String yourdata which is what will be
// sent in your POST request
yourdata = y + yourarduinodata2;
yourdata2 = x + yourarduinodata;
httpRequest();
}
void loop() {
}
void printWifiStatus() {
// print the SSID of the network you're
attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
// this method makes a HTTP connection to the
server
void httpRequest() {
// if there's a successful connection, send
the HTTP PUT request
if (client.connect(server, 80)) {
Serial.println("connecting...");
//
// EDIT: the URL to the location of your
insert_mysql.php on your web-host
//
client.println("POST /test.php HTTP/1.1");
//
// EDIT: Host to match your domain
//
client.println("Host: yourdomain.com");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.println("Content-Type:
application/x-www-form-urlencoded;");
client.print("Content-Length: ");
client.println(yourdata.length());
client.println();
client.println(yourdata);
client.println(yourdata2.length());
client.println();
client.println(yourdata2);
}
else {
// if you couldn't make a connection:
Serial.println("Connection failed");
Serial.println("Disconnecting.");
client.stop();
}
}