2012-04-20 86 views
1

附近使用正确的语法我已经将此数据插入数据库的代码,但即使我已经多次检查语法,我仍然收到此错误,任何人都可以帮助我?
错误:您在SQL语法中有错误;检查对应于您的MySQL服务器版本的手册,以便在

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 'cou ?','output','input','new line', 'break','output','Multiable_Choise')' at line 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); 
      ?> 
+0

的意见面前:正如你可能已经注意到,该错误消息状态(除其他事项外)的行号。这是一个非常有用的信息,也是如何编写查询的提示:线条越多,查找错误就越容易。更多,当然是合理的。 – bostaf 2012-04-20 23:42:07

+0

你能告诉我们你桌子的结构吗?可能C_ID和E_NO是整数,并且您试图将字符串插入到这些字段中。 – Virendra 2012-04-21 02:26:25

回答

2

有一个'失踪的{$Question['Question']}'

+0

我已修复它,但它没有插入E_no&courseId! – 2012-04-20 23:41:36

+0

@ SaraS'h就在'$ sql =“INSERT ...'之前,你可以var_dump($ E_no);''和'var_dump($ courseId);'?这两个变量都是有条件地设置的。没有设置,'var_dump'会回显两个变量的值。 – bostaf 2012-04-20 23:46:34

相关问题