Reputation: 382
I am trying to update values in a database but only get this error. The database connects with no error, but with trying to update values it breaks. Here is a picture of the browser error and the update.php
<?php
$speed = $_GET["speed"];
$lat = $_GET["lat"];
$lng = $_GET["lng"];
$currentTime = time();
echo $speed . "<br>";
echo $lat . "<br>";
echo $lng . "<br>";
include "db_connect.php";
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE where-am-I SET time='$currentTime' WHERE id=1";
if ($conn->query($sql) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $conn->error;
}
$conn->close();
?>
Upvotes: 0
Views: 38
Reputation: 5358
MySQL (and MariaDB) allow only 0-9, a-z, A-Z, $ and _ in unquoted object names. (See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html).
You can use hyphens if you wrap the name in backticks
For example
SELECT * FROM `table-name-with-hyphens`
I'd recommend you refrain from using hyphens and other special characters in your object names to avoid other possible conflicts.
Upvotes: 2