简体   繁体   English

更新数据库中的值时 SQL 语法错误

[英]SQL syntax error when updating value in database

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

在此处输入图像描述

<?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();
?>

MySQL (and MariaDB) allow only 0-9, az, AZ, $ and _ in unquoted object names. MySQL(和 MariaDB)仅允许在未加引号的 object 名称中使用 0-9、az、AZ、$ 和 _。 (See https://dev.mysql.com/doc/refman/8.0/en/identifiers.html ). (参见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.我建议您不要在 object 名称中使用连字符和其他特殊字符,以避免其他可能的冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM