2

I have code below:

  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)");
    }

When executing that query I got the following error:

 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

How can I fix this error?

2
  • you are missing single quote, like '$created', '$modified' Commented Nov 6, 2014 at 8:08
  • dump your query, please Commented Nov 6, 2014 at 8:11

1 Answer 1

1

You're missing quotes around the dates in order to make them character literals:

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')");
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.