So I have a NodeMCU programmed to send float data to a hosted MySQL Database. I made it so that the value being sent is printed in the serial monitor for me to make sure that it's correct. Up until this point, everything works fine.
However, when I check the recorded values, it would only have '1.00'. For example, the supposed recorded value according to the serial monitor should be '12.65', but the database would have '1.00' instead. I tried converting the variable type to float using (float) $var
and floatval($var)
but it still had the same result. What am I missing?
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$api_key = test_input(isset($_POST["api_key"]));
if ($api_key = $api_key_value)
{
$var = test_input(isset($_POST["DB_Column"]));
$insert_var = mysqli_query($conn, "INSERT INTO SCHEMA.Table(Time, Record)
VALUES(CURRENT_TIMESTAMP, '" . $var . "')
;");
if (!$insert_var)
{
die("Query failed: " . mysqli_error($conn));
}
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}