Can't send a string of data to MySQL database via ethernet shield

Hi guys, I’ve been trying to send a message such as “La poubelle est vide” to be stored in a database but nothing is being saved in the database. If I use underscore, example “la_poubelle_est_vide” it works, but I want instead of using underscore, i use space between the words.

Here is the code I’m using to send the data:

void sending_To_phpmyadmindatabase(String message)   //CONNECTING WITH MYSQL
 {
   if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    Serial.print("GET /testcode/dht.php?message=");
    client.print("GET /testcode/dht.php?message=");     //YOUR URL
    Serial.println(message);
    client.print(message);
    client.print("&latitude=");
    Serial.println("&latitude=");
    client.print(latitude,6);
    Serial.println(latitude,6);
    client.print("&longitude=");
    Serial.println("&longitude=");
    client.print(longitude,6);
    Serial.println(longitude,6);
    client.print(" ");      //SPACE BEFORE HTTP/1.1
    client.print("HTTP/1.1");
    client.println();
    client.println("Host: 192.168.1.10");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }}

php code if it is required:

<?php
class dht11{
 public $link='';
 function __construct($message, $latitude, $longitude){
  $this->connect();
  $this->storeInDB($message, $latitude, $longitude);
 }
 
 function connect(){
  $this->link = mysqli_connect('localhost','root','') or die('Cannot connect to the DB');
  mysqli_select_db($this->link,'poubelle_connecter') or die('Cannot select the DB');
 }
 
 function storeInDB($message, $latitude, $longitude){
  $query = "insert into donnee SET message= '".$message."', latitude='".$latitude."', longitude='".$longitude."'";
  $result = mysqli_query($this->link,$query) or die('Errant query:  '.$query);
 }
 
}

$dht11=new dht11($_GET['message'],$_GET['latitude'], $_GET['longitude']);


?>

Hello,

message should be url-encoded (spaces replaced by %20, etc)

like message=“test%20code”, is that what you mean?

Thanks it works

1 Like

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.