更新查询时出现MySQL语法错误

时间:2015-09-08 09:47:13

标签: mysql

我的查询出错了,我不明白问题是什么。我得到的错误是

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 = '55', atkspeed = '0.95', m_damage = '0', p_damage = '38', mprotection = ' at line 1

虽然我正在使用的代码是这个

 $id = mysql_real_escape_string($_POST["id"]);
 $value0 = mysql_real_escape_string($_POST["value0"]);
 $value1 = mysql_real_escape_string($_POST["value1"]);
 $value2 = mysql_real_escape_string($_POST["value2"]);
 $value3 = mysql_real_escape_string($_POST["value3"]);
 $value4 = mysql_real_escape_string($_POST["value4"]);
 $value5 = mysql_real_escape_string($_POST["value5"]);
 $value6 = mysql_real_escape_string($_POST["value6"]);
 $value7 = mysql_real_escape_string($_POST["value7"]);
 $value8 = mysql_real_escape_string($_POST["value8"]);
 $value9 = mysql_real_escape_string($_POST["value9"]);
 $value10 = mysql_real_escape_string($_POST["value10"]);


 $query="UPDATE char_stats SET vita = '$value0', mana = '$value1', speed = '$value2', range = '$value3', atkspeed = '$value4', m_damage = '$value5', p_damage = '$value6', mprotection = '$value7', pprotection = '$value8', hp5 = '$value9', mp5 = '$value10' WHERE id_char_stats='$id'";

我正在使用其他非常相似的查询,所以我不知道问题可能是什么。我在思考char_stats的下划线,所以我尝试使用

char\_stats

逃跑,但无论如何都没有用。

提前致谢

1 个答案:

答案 0 :(得分:1)

create table t11
(
    id int not null,
    `range` int not null,
    speed int not null
);

update t11 set range='11', speed=1; -- blows up
update t11 set `range`='11', speed=1; -- fine
update t11 set `range`=11, speed=1; -- fine

商店的道德:反击范围。即使创建表没有它也会爆炸。

查看mysql关键字和保留字hereRange就是其中之一。

所以你的查询将成为:

$query="UPDATE char_stats SET vita = '$value0', mana = '$value1', speed = '$value2', `range` = '$value3', atkspeed = '$value4', m_damage = '$value5', p_damage = '$value6', mprotection = '$value7', pprotection = '$value8', hp5 = '$value9', mp5 = '$value10' WHERE id_char_stats='$id'";