我正在测试将变量插入数据库。使用匹配的列正确设置数据库。执行以下代码时,出现此错误:
<?php session_start();
$con = mysqli_connect('******', '*****', '*****', '*****'); //I erased my username and password stuff but I'm 100% sure they work in my actual code
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$subject = "biology";
$sql="INSERT INTO scores (index, userid, test, score, date) VALUES ('','','$subject','','')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con)); //it looks like this line is producing the error messege
}
?>
错误:
答案 0 :(得分:2)
index
是reserved word。您可以指定某些内容是列/表/等。标识符包装在后面的标记中:
INSERT INTO `scores` (`index`, `userid`, `test`, `score`, `date`) VALUES ('','','$subject','','')