【问题标题】:PHP MySQL Insert databasePHP MySQL 插入数据库
【发布时间】:2015-01-02 15:57:56
【问题描述】:

我的代码如下:

  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

我该如何解决这个错误?

【问题讨论】:

  • 你缺少单引号,比如'$created', '$modified'
  • 请转储您的查询

标签: php mysql arrays insert


【解决方案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')");
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-27
    • 1970-01-01
    相关资源
    最近更新 更多