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

时间:2013-03-12 20:58:03

标签: php mysql syntax-error

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

错误:

  

[INSERT INTO'PlayerSats'中发生错误   (用户名,字符,FirstPlay)VALUES('WaxyChicken','20','FALS')]:   您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近''PlayerSats'(用户名,字符,FirstPlay)值   ('WaxyChicken','20','FALS')'在第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
);

3 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:1)

表名不包含在引号中。应该只是

INSERT INTO PlayerSats (username,character,FirstPlay) VALUES ('WaxyChicken','20','FALS')

答案 2 :(得分:1)

您的列“字符”在MySQL中是reserved word ...您需要通过将其封闭在后面的标记或使用其他列名称来逃避

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