Good evening guys, I'm trying to give an INSERT in a mysql database with parameters that I pass through arduino via GET to a php page with the name of salvardados.php I can not think of a solution to that. Because in my view it is right, but it does not insert from any forna
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 0, 105 };
byte servidor[] = { 192, 168, 0, 103 };
EthernetClient cliente;
float sensor1 = 0;
float sensor2 = 0;
float sensor3 = 0;
void setup() {
Serial.begin(9600);
Ethernet.begin(mac, ip);
}
void loop() {
char comando = Serial.read();
if (comando == 'a') {
if (cliente.connect(servidor, 9080)) {
Serial.println("conectado");
sensor1 = sensor3 + 5;
sensor2 = sensor1 + 5;
sensor3 = sensor2 + 5;
cliente.print("GET /arduino/salvardados.php?");
cliente.print("sensor1=");
cliente.print(sensor1);
cliente.print("&sensor2=");
cliente.print(sensor2);
cliente.print("&sensor3=");
cliente.println(sensor3);
Serial.print("GET /arduino/salvardados.php?");
Serial.print("sensor1=");
Serial.print(sensor1);
Serial.print("&sensor2=");
Serial.print(sensor2);
Serial.print("&sensor3=");
Serial.println(sensor3);
cliente.stop();
} else {
Serial.println("falha na conexao");
}
}
}
php: include_once ("connection.php");
$sensor1 = $_GET['sensor1'];
$sensor2 = $_GET['sensor2'];
$sensor3 = $_GET['sensor3'];
$sql = "INSERT INTO tabelaarduino (sensor1, sensor2, sensor3) VALUES('$sensor1','$sensor2','$sensor3')";
mysqli_query($conectar, $sql);
echo $sql;