找了很久都没有找到解决方案
Undefined index: coursename in C:\wamp\www\StudentInformationProject\Student_new\courseinsert.php on line 17
Error: 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 '1'>
这是代码
if(isset($_POST["button"]))
{
$sql="INSERT INTO course(courseid, coursename, comment, coursekey)
VALUES('".$_POST['courseid']."','".$_POST['coursename']."',
'".$_POST['comment']."','".$_POST['coursekey']."')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
else
{
echo "1 record Inserted Successfully...";
}
}
最佳答案
您的一个替代变量中有一个双引号。鉴于错误消息,它可能看起来像:
foo "1" bar
你应该通过将它们加倍来转义这些字符,所以它看起来像:
foo ""1"" bar
关于php - SQL 语法错误和未定义索引错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17306819/