2015-05-20 127 views
-3

當我要點擊細節我得到這個錯誤:錯誤在SQL查詢語法

您的SQL語法錯誤;請檢查手冊, 對應於您的MySQL服務器版本的正確語法使用 附近'和sq.testid = 5),0)作爲從學生om作爲s,測試爲t, 作爲子,學生在線1

$result=executeQuery("select s.stdname,s.nume_student,s.prenume_student, 
     t.testname, t.testdesc,sub.subname,sub.subdesc,sub.an, 
     DATE_FORMAT(st.starttime,'%d %M %Y ') as stime, 
     DATE_FORMAT(st.starttime,' %H:%i:%s') as stimes, 
     TIMEDIFF(st.endtime,st.starttime) as dur, 
     (select sum(marks) 
       from question 
       where testid=".$_REQUEST['details'].") as tm, 
     IFNULL((select sum(q.marks) 
       from studentquestion as sq, question as q 
       where sq.testid=q.testid and sq.qnid=q.qnid 
        and sq.answered='answered' and sq.stdanswer=q.correctanswer 
        and sq.stdid=".$_REQUEST['stdid']." 
        and sq.testid=".$_REQUEST['details']."),0) as om 
      from student as s,test as t, subject as sub,studenttest as st 
       where s.stdid=st.stdid and st.testid=t.testid 
        and t.subid=sub.subid and st.stdid=".$_REQUEST['stdid']." 
        and st.testid=".$_REQUEST['details'].";") ; 

我知道這個問題是sq.stdid=".$_REQUEST['stdid']."st.stdid=".$_REQUEST['stdid'].",但我不知道如何解決它。

+1

每當你編輯..試圖刪除滾動......這是非常惱人 –

+0

發現SQL注入。錯了')'發現了。發現可憐的桌子設計:( – DanFromGermany

+0

與你的問題沒有關係,但如果你使用'$ _REQUEST',你應該看看這裏:http://stackoverflow.com/questions/2142497/whats-wrong-with-using-請求 – Lupin

回答

0

調試的典型方法是打印出生成的查詢。

從我所看到的(從你的錯誤消息)似乎這裏taht:

nd sq.testid=".$_REQUEST['details']."),0) as om 

收盤),0)前似有不妥。