【发布时间】:2012-05-02 12:55:42
【问题描述】:
我有这段代码可以将数据插入数据库,但即使我已经检查了很多次语法,我仍然收到这个错误,谁能帮助我?
错误:
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'cou ?'、'output'、'input'、'new line'、'break'、'output'、'Multiable_Choise')' 附近使用的正确语法4
<?php
$connectdb = mysql_connect('localhost','root','sara', true ) or die ("Not Connect");
if (!$connectdb)
{
die('Could not connect :'. mysql_errno());
}
$selestdb = mysql_select_db('iexa', $connectdb) or die ("not selected database");
$chois_1 = array();
$chois_2 = array();
$chois_3 = array();
$chois_4 = array();
$Question = array();
$correct = array();
$correct['Correct_Answer']= mysql_real_escape_string($_POST['Correct_Answer']) ;
$Question['Question']= mysql_real_escape_string($_POST['Question']) ;
$chois_1['Choise_1']= mysql_real_escape_string($_POST['Choise_1']) ;
$chois_2['Choise_2']= mysql_real_escape_string($_POST['Choise_2']) ;
$chois_3['Choise_3'] = mysql_real_escape_string($_POST['Choise_3']) ;
$chois_4['Choise_4'] = mysql_real_escape_string($_POST['Choise_4']) ;
if (isset($_POST['E_No'])) {
$E_no = $_POST['E_No'];
}
if (isset($_REQUEST['courseID'])) {
$courseId = $_REQUEST['courseID'];
}
$sql ="INSERT INTO question_bank (C_ID ,E_No , Question , Choise_1 , Choise_2 , Choise_3 , Choise_4 , Correct_Answer
, Question_Type )
VALUES
('$courseId','$E_no', {$Question['Question']}','{$chois_1['Choise_1']}','{$chois_2['Choise_2']}','{$chois_3['Choise_3']}',
'{$chois_4['Choise_4']}','{$correct['Correct_Answer']}','$_POST[Question_Type]')
";
if (!mysql_query($sql,$connectdb))
{
die ('Error :'.mysql_error());
}
echo "The Qustion is saved";
echo ' <br />
<a href="question.htm" >Add Another Question</a> <br />
<a href="ManageStudents.htm">Manage Students</a> <br />
<a href="Instructor.htm">Home</a>
';
mysql_close($connectdb);
?>
【问题讨论】:
-
一个建议:您可能已经注意到,错误消息说明(除其他外)行号。这是一个非常有用的信息,也是关于如何编写查询的提示:行越多越容易找到错误。更多,当然是以合理的方式。
-
你能告诉我们你的表的结构吗?可能 C_ID 和 E_NO 是整数,您正在尝试将字符串插入这些字段。
标签: php mysql mysql-error-1064