2014-11-06 158 views
2

我有下面的代碼:PHP MySQL的數據庫插入

for($x=0; $x<=count($_POST["id_k"])-1; $x++) { 
    $db->query("INSERT INTO evaluation (id_e, id_k, id_p, bulan, tahun, k1, k2, k3, k4, 
     k5, k6, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, e1, e2, e3, e4, e5, e6, e7, 
     e8, e9, e10, e11, e12, f1, f2, f3, remark, iplog, created, modified) 

     VALUES (null, '$id_k[$x]', $id_p, $bulan, $tahun, '$k1[$x]', '$k2[$x]', 
     '$k3[$x]', '$k4[$x]', '$k5[$x]', '$k6[$x]', '$s1[$x]', '$s2[$x]', '$s3[$x]', '$s4[$x]', 
     '$s5[$x]', '$s6[$x]', '$s7[$x]', '$s8[$x]', '$s9[$x]', '$s10[$x]', '$e1[$x]', '$e2[$x]', 
     '$e3[$x]', '$e4[$x]', '$e5[$x]', '$e6[$x]', '$e7[$x]', '$e8[$x]', '$e9[$x]', '$e10[$x]', 
     '$e11[$x]', '$e12[$x]', '$f1[$x]', '$f2[$x]', '$f3[$x]', $remark, $iplog, 
     $created, $modified)"); 
    } 

當執行該查詢我得到了以下錯誤:

Warning: 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 '14:59:57, ::1, 
2014-11-06 14:59:57, 2014-11-06 14:59:57)' at line 2 in 

我怎樣才能解決這個問題?

+0

你缺少單引號,像'「$創建」,「$ modified'' – waki 2014-11-06 08:08:17

+0

轉儲你的查詢,請 – 2014-11-06 08:11:07

回答

1

你錯過了日期,各地的報價,以使他們字符文字:

for($x=0; $x<=count($_POST["id_k"])-1; $x++) { 
    $db->query("INSERT INTO evaluation (id_e, id_k, id_p, bulan, tahun, k1, k2, k3, k4, 
     k5, k6, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, e1, e2, e3, e4, e5, e6, e7, 
     e8, e9, e10, e11, e12, f1, f2, f3, remark, iplog, created, modified) 

     VALUES (null, '$id_k[$x]', $id_p, $bulan, $tahun, '$k1[$x]', '$k2[$x]', 
     '$k3[$x]', '$k4[$x]', '$k5[$x]', '$k6[$x]', '$s1[$x]', '$s2[$x]', '$s3[$x]', '$s4[$x]', 
     '$s5[$x]', '$s6[$x]', '$s7[$x]', '$s8[$x]', '$s9[$x]', '$s10[$x]', '$e1[$x]', '$e2[$x]', 
     '$e3[$x]', '$e4[$x]', '$e5[$x]', '$e6[$x]', '$e7[$x]', '$e8[$x]', '$e9[$x]', '$e10[$x]', 
     '$e11[$x]', '$e12[$x]', '$f1[$x]', '$f2[$x]', '$f3[$x]', $remark, $iplog, 
     '$created', '$modified')"); 
    } 
+0

非常感謝...解決了。 :-) – 2014-11-06 08:22:52