dsc862009 2014-07-09 21:04
浏览 46
已采纳

获取语​​法错误,但我找不到语法错误

So I'm working on an editor for a friend of mine, and I'm getting a strange Syntax error. It's strange because I'm currently creating an NPC editor using the shell of the Item editor I made a while back. That's saying I literally just changed the variables and changed everything that said 'item' to 'npc'. However, I'm getting a syntax error at a random column and I can't find out what the error is. It's in the editing section of the editor(lol). The delete and create parts of the editor work fine.

}else if($state == "edit")
{
    $editsql = "UPDATE npcs SET name='" . $name . "', description='" . $description . "', gender=" . $gender . ", size=" . $size . ", dialog='" . $dialog . "', hair_style=" . $hair_style . ", hat=" . $hat . ", top=" . $top . ", bottom=" . $bottom . ", movement_pattern=" . $movement_pattern . ", behavior=" . $behavior . ", range=" . $range . ", uses_special_pokemon=" . $uses_special_pokemon . ", pokemon_1=" . $pokemon_1 . ", pokemon_2=" . $pokemon_2 . ", pokemon_3=" . $pokemon_3 . ", pokemon_4=" . $pokemon_4 . ", pokemon_5=" . $pokemon_5 . ", pokemon_6=" . $pokemon_6 . " WHERE id=" . $id;

this is the error:

Could not edit npc ID 3 : 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 'range=0, uses_special_pokemon=0, pokemon_1=1, pokemon_2=1, pokemon_3=1, pokemon_' at line 1

I can't quite figure out what it's calling out near 'range' and range itself looks fine to me, so I don't see an error at all. It's most likely something completely obvious that I'm just overlooking as usual, but I'm stumped.

  • 写回答

1条回答 默认 最新

  • duanliaogui4133 2014-07-09 21:16
    关注

    You'll want to rename range to range_, because Range is a SQL reserved word. You could enclose it in backticks, which are different than single quotes. ` VS ' ...

    If you seperate the query into multiple lines your error message will tell you where it failed closer to where the actual error was. It's a one-liner, so it tells you error exists on line 1. Typically, seperate clauses, i.e.

     select xxxx
     from yyyy
     where  xxxx = zzzz
    

    then you'll know it's an error in syntax and in what clause.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能