【发布时间】:2015-01-14 18:49:44
【问题描述】:
所以我正在使用数据库并且刚刚得到这个错误代码:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ',,,)' 附近使用正确的语法
我在这里搜索并注意到很多人都遇到了同样的问题,但我无法确定在我的特定情况下我需要更改什么。
编辑:对不起,我一开始输入了错误的版本。现已修复。
我得到此错误代码的 .php 文件:
<?PHP
require_once("base.php");
$first = $_REQUEST["First"];
$second = $_REQUEST["Second"];
$third = $_REQUEST["Third"];
$fourth = $_REQUEST["Fourth"];
$fifth = $_REQUEST["Fifth"];
$SQL="insert into batch(first,second,third,fourth,fifth)
values($first,$second,$third,$fourth,$fifth);";
mysql_query($SQL)or die(mysql_error());
header("location:12345.php");
?>
这里有什么问题?
【问题讨论】:
-
$first、$second、$third、$fourth和$fifth的值没有在您的代码中的任何地方定义,那么您期望什么?您的意思是使用$hemma、$borta、$arena、$ansvarigID和$publiksiffror? -
你最好祈祷没有讨厌的人访问你的网站,因为......就像...... Little Bobby Tables
-
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 '- 当然。不要像ints 这样对待字符串。 -
学习使用 MySQLi 或 PDO(不是已弃用的旧 MySQL 接口);并学习使用参数化语句,这样您就无需记住转义数据或引用您的字符串值
-
您不仅在这里使用了错误的变量,而且在查询中也没有正确分离它们。更进一步的是
$SQL="insert into matcher(first,second,third,fourth,fifth)values('$first','$second','$third','$fourth','$fifth');";,要聪明一点,也可以转义你的变量,再加上mysqli或pdo。