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 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP