Hi, everyone. I need to send data from sensors on Arduino to phpmyadmin database. I have managed to send over a single value to a one-column-database but I'm unable to send a set of three different values to a three-column-database.
So I decided to debug my Arduino code and send three pre-initialised values to the database. As it turns out, I'm not able to do that either. I'm able to see the values being displayed on the serial monitor but they are not being uploaded to the database. Please help me.
The Arduino sketch, the serial monitor data and the PHP code are mentioned below and I have attached a screenshot of the table structure from phpmyadmin.
Arduino sketch:
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,,);
char server[] = "192.168.**.";
char pid='A';
char pname='B';
char cat='C';
EthernetClient client;
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
delay(5000);
}
void loop()
{
if (client.connect(server, 80))
{
Serial.println("Connection Established");
client.print("GET /abc.php?");
client.print("pid=");
client.print(pid);
client.print("&pname=");
client.print(pname);
client.print("&cat=");
client.print(cat);
client.stop();
Serial.println(pid);
Serial.println(pname);
Serial.println(cat);
pid+=3;
pname+=3;
cat+=3;
}
else
{
Serial.println("Connection failed\n");
client.stop();
}
delay(10000);
}
Serial monitor data:
Connection Established
A
B
C
Connection Established
D
E
F
Connection Established
G
H
I
PHP code:
<?php $dbusername = "manager"; $dbpassword = "managerstock"; $server = "localhost"; $dbconnect = mysqli_connect($server, $dbusername, $dbpassword); $dbselect = mysqli_select_db($dbconnect, "stock"); $pid = $_GET['pid']; $pname = $_GET['pname']; $cat = $_GET['cat']; $sql = "INSERT INTO stock.inventory (pid, pname, cat) VALUES ('$pid','$pname','$cat')"; mysqli_query($dbconnect, $sql); ?>Please help me ???
There's nowhere left that I haven't looked and I'm still trying.