0

I have some issues regarding data upI get this error:

Error: INSERT INTO TEMPERATURE (time, temperature) VALUES (1969-12-31 19:00:00, ) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '19:00:00, )' at line 2

This is the code I am using:

<?php
//GET data from the module
$time = $_GET["time"] ;
$temperature = $_GET["temperature"] ;

//Change the time atributes
$time = date("Y-m-d H:i:s", strtotime($time-30000));

//MySQL data
$servername = "host.com";
$username = "admin";
$password = "password";
$dbname = "mobile";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Append data
$sql = "INSERT INTO GPS (time, temperature)
VALUES ($time, $temperature)";

// Check
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

Where the "GET" temperature has the following format: YYYYmmddHHMMSS in UTC and I want to display UTC-3 (that is why I subtract 30 000).

This is the SQL table

James Z
  • 12,209
  • 10
  • 24
  • 44
Federico
  • 55
  • 1
  • 7
  • 1
    1) your time value isn't quoted, 2) $_GET['temperature'] doesn't appear to be set. – Jonnix Jun 10 '16 at 15:22
  • you're not inserting a date/time, you're inserting a MATH expression. unquoted dates are simply a subtraction operation. `'2016-06-10'` is date, `2016-06-10` is `2016 minus 6 minus 10` and evaluates to `2000` – Marc B Jun 10 '16 at 15:23
  • I sure hope those aren't actual login credentials. If they are, you had better go change those.... RIGHT NOW. – Funk Forty Niner Jun 10 '16 at 15:27

0 Answers0