doudou1309 2013-03-12 20:58
浏览 69
已采纳

我的PHP / MySQL语法错误在哪里? [关闭]

I may have just been looking at this for too long, but I fail to see the error. Any help would be appreciated.

The 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

Do note that "PlayerSats" is not a typo and is properly capitalized.

The Code:

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";
}

The table structure:

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条回答 默认 最新

  • dongliao3450 2013-03-12 21:20
    关注

    Your column "character" is a reserved word in MySQL... you either need to escape by enclosing it in back-ticks or use another column name

    $sql = "INSERT INTO $PlayerStats (username,`character`,FirstPlay) VALUES ('$username','$Char','FALS')";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件