Click here to Skip to main content
14,872,753 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Now, I'm developing Temperature and Humidity Monitoring Website using ESP32 and DHT11 as a sensor, but i've failed when i tried to send Temperature and Humidity data from censor to Mysql database. Here's the error message from arduino :

Invalid query: Data truncated for column 'temperature' at row 1


I've tried configure write-data.php as a connector between ESP32 and Mysql below :

What I have tried:

<?php

    //Variabel database\
    $servername = "xxx";
    $username = "xxx";
    $password = "xxx";
    $dbname = "xxx";

    $conn = mysqli_connect("$servername", "$username", "$password","$dbname");

// Prepare the SQL statement

$result = mysqli_query ($conn,"INSERT INTO datasensor (temperature) VALUES ('".$_GET["temperature"]."')");

if (!$result)
    {
        die ('Invalid query: '.mysqli_error($conn));
    }
?>
Posted
Updated 27-Mar-20 2:34am

1 solution

Don't do it like that!

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

PHP: SQL Injection - Manual[^]


As to your error message, it indicates that you're trying to insert data which is longer than the maximum length of the column. You'll need to debug your code to see what data is being sent, and update your database schema accordingly.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900