php - 错误 : You have an error in your SQL syntax; check your MySQL server version for the right syntax to use near

标签 php mysql sql

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 '('RealName') VALUES ('Louise T') WHERE SteamID='7656119801402xxxx'' at line 1

$mysql_hostname = "localhost";
$mysql_user = "xxxx";
$mysql_password = "xxxx";
$mysql_database = "xxxx";
$prefix = "";
$conn = mysql_connect($mysql_hostname, $mysql_user, $mysql_password);
$connect = mysql_select_db($mysql_database, $conn);


$realname = 'Louise T';
$steamid = '7656119801402xxxx';

$sql="UPDATE users SET ('RealName') VALUES ('". mysql_real_escape_string($realname)  ."') WHERE SteamID='$steamid'";
if (!mysql_query($sql))
{
    die('Error: ' . mysql_error());
} else {
    header("Location: index.php");
    exit();
}

不知道这是什么原因造成的?我一直在检查每个单词是否干扰了某些 MySQL 命令,但似乎仍然出现此错误。

这是我在网上找到的一些规则:

  1. 您省略或包含了不必要的符号:!@#$%^&*()-_=+[]{}|;:'",<>/?
  2. 放错位置、遗漏或不必要的关键字:select、into 或无数其他关键字。
  3. 您的查询中有看起来像 ascii 字符但无法识别的 unicode 字符。
  4. 关键字之间错位、缺失或不必要的空格或换行符。
  5. 不匹配的单引号、双引号、圆括号或大括号。

但我真的不认为有类似的东西吗?

最佳答案

您的更新查询无效,因为 SET ('RealName') VALUES 不是有效的语法 more details

像这样使用更新:-

UPDATE users SET RealName='$realname' WHERE SteamID='$steamid'

对于插入:-

Insert into users (RealName) values ('$steamid')

关于php - 错误 : You have an error in your SQL syntax; check your MySQL server version for the right syntax to use near,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33591245/

相关文章:

mysql - SQL INNER JOIN 和 AVG() 返回错误数据

mysql - mysql 列数据类型对保持效率很重要吗?

mysql - SQL 中同一列中多个值的条件

javascript - symfony2如何通过javascript访问twig路径

Java 中 "PBKDF2WithHmacSHA256"的 PHP 替代方案

php - 如何提供合适的查询来检查房间可用性

mysql 匹配多个and 和or

php - 如何在mysql中显示连续日期,如果日期不存在于表中

sql - 从表中的多个 XML 行中选择单个 XML

MySQL 检索特定字符串之前的值