它不断收到此SQL错误,但我非常确定查询中没有错误.我一直盯着它看太久了.还有其他可能导致这种情况的事吗?
INSERT INTO game_data (clue, image, answer, wrong, right) VALUES ('asdf', 'asdf', 'asdf', 'assdf', 'asdf')
Invalid Query: 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 'right) VALUES ('asdf', 'asdf', 'asdf', 'assdf', 'asdf')' at line 1
Run Code Online (Sandbox Code Playgroud)
我用这个确切的代码运行其他查询,只是交换变量,它的工作原理.
并且为了更好的衡量,有一个PHP生成这个:
$sql = "INSERT INTO game_data (clue, image, answer, wrong, right) VALUES
('" . $clue . "', '" . $image . "', '" . $answer . "', '" . $wrong . "', '" . $right . "')";
Run Code Online (Sandbox Code Playgroud)
Rah*_*thi 11
right是MYSQL中的保留关键字.你需要使用这样的反引号来逃避它:
INSERT INTO game_data (`clue`, `image`, `answer`, `wrong`, `right`) VALUES
Run Code Online (Sandbox Code Playgroud)
注意:尽量避免将列命名为保留关键字名称.