php - 我的 PHP/MySQL 语法错误在哪里?

标签 php mysql syntax-error

<分区>

我可能已经看这个太久了,但我没有看到错误。任何帮助将不胜感激。

错误:

Error occurred in [INSERT INTO 'PlayerSats' (username,character,FirstPlay) VALUES ('WaxyChicken','20','FALS')]: 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 ''PlayerSats' (username,character,FirstPlay) VALUES ('WaxyChicken','20','FALS')' at line 1

请注意,“PlayerSats”不是拼写错误,而是正确地大写。

代码:

if ($Funct == "SETFIRSTPLAY") {
    $sql = "INSERT INTO $PlayerStats (username,character,FirstPlay) VALUES ('$username','$Char','FALS')";
    mysql_query($sql) or die("Error occurred in [$sql]: " . mysql_error());
    echo "SUCCESS";
}

表结构:

CREATE table PlayerStats (
    ID int(10) unsigned not null auto_increment,
    username char(20) not null default '' utf8_general_ci,
    character char(2) not null default '00' utf8_general_ci,
    invLand char(115) not null default '000:99' utf8_general_ci,
    FirstPlay char(4) not null default 'true' utf8_general_ci,
    Bank int(20) unsigned not null default 2000
);

最佳答案

您在 PlayerStats 前面有一个 $。尝试:

$sql = "INSERT INTO PlayerStats (username,character,FirstPlay) VALUES ('$username','$Char','FALS')";

关于php - 我的 PHP/MySQL 语法错误在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15371984/

相关文章:

php - 使用php插入sql数据库时出错

带有必填字段的 PHP 表单

php - Heroku PHP 应用程序崩溃 bash : vendor/bin/heroku-php-apache2: No such file or directory

php - 从mysql表中获取列类型为 "timestamp "的数据?

mysql - 使用Docker进行本地Web开发的HTTPS和MySql问题

php - PDO 执行 mysql cli 不能执行的语句

php - 将数组值和其他表单值插入到两个不同的mysql表中

syntax-error - 用5.5编写的PHP函数在升级到7.0时抛出错误

php - MySQL 查询从一个表中获取最佳排名并更新结果另一个表

python - PyCharm 警告 "End of statement expected"类型提示内部