Mysql插入不起作用(错误说错误的语法)

时间:2015-06-17 19:33:04

标签: php mysql

我正在测试将变量插入数据库。使用匹配的列正确设置数据库。执行以下代码时,出现此错误:

 <?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
}


?>

错误:

enter image description here

1 个答案:

答案 0 :(得分:2)

indexreserved word。您可以指定某些内容是列/表/等。标识符包装在后面的标记中:

INSERT INTO `scores` (`index`, `userid`, `test`, `score`, `date`) VALUES ('','','$subject','','')