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条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化