dongzhuo6137 2010-07-31 18:16
浏览 50
已采纳

将多个数组插入数据库时​​出现问题

I was inserting multiple arrays into my database using this code:

$queries_cols = array(); 

for($i=0; $i<count($cols); $i++) 
{ 
    $queries_cols [] = "('".$cols[$i]."','".$int_manha1_1[$i]."','".$int_manha1_2[$i]."','" .$int_tarde2_1[$i]."','".$int_tarde2_2[$i]."','".$h1_1[$i].$h1_2[$i]."','".$h2_1[$i].$h2_2[$i]."')" ; 
}

$query_col = "INSERT into cols_ponto_diaria values '".implode(",", $queries_cols)."'";

$result = mysql_query($query_col) or die("Erro: ".mysql_error());

And when I submit the form it output an error:

Erro: 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 ''('Ricardo','08:30:00','12:15:00','14:45:00','18:00:00','0115','1215')'' at line 1

Can anyone find where is the error? I've tried a few solutions but without any success.

Thanks in advance.

  • 写回答

3条回答 默认 最新

  • duanjian4331 2010-07-31 18:24
    关注

    You could easily find it by printing $query_col as soon as you have it ready.

    Anyway, the error I believe is in the implode() call. You don't need the extra quotes.

    So instead of

    $query_col = "INSERT into cols_ponto_diaria values '".implode(",", $queries_cols)."'";
    

    try

    $query_col = "INSERT into cols_ponto_diaria values ".implode(",", $queries_cols);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大