duandongji2231 2013-04-27 09:21
浏览 36
已采纳

PHP不会在foreach循环中插入mySQL

I have a string array and I am trying to insert each data in this array into mySQL inside a foreach loop. But I recognized It doesn't insert all of them. Sometimes insert all, sometimes insert some of them. My code is below. Please let me figure out what my problem here is.

foreach($cbarray as $chvalue){
     list($kid, $odemeopt) = explode('-',$chvalue);
     $i_tr="trp".$kid;
     $i_en="enp".$kid;
     $i_fr="frp".$kid;

    $tr_kargop=doubleval($_POST[$i_tr]);
    $en_kargop=doubleval($_POST[$i_en]);
    $fr_kargop=doubleval($_POST[$i_fr]);                                                            

    if($odemeopt==1){
        $ik_tr="trk".$kid;
        $ik_en="enk".$kid;
        $ik_fr="frk".$kid;                          
    }
    $tr_kargoextra=doubleval($_POST[$ik_tr]);
    $en_kargopextra=doubleval($_POST[$ik_en]);
    $fr_kargopextra=doubleval($_POST[$ik_fr]);                                                              

$myquery = "INSERT INTO item_kargo(product_id,kargo_id,kargo_priceTR,kargo_priceEN,kargo_priceFR,odemefarkiTR,odemefarkiEN,odemefarkiFR) VALUES ('$next_increment','$kid','$tr_kargop','$en_kargop','$fr_kargop','$tr_kargoextra','$en_kargopextra','$fr_kargopextra')";
   echo "<h2>".$myquery."</h2>";

   $kargo_bilgisi=mysql_query($myquery) or die("!!hata kargooo :".mysql_error());
 }

This is the result of myquery

INSERT INTO item_kargo(product_id,kargo_id,kargo_priceTR,kargo_priceEN,kargo_priceFR,odemefarkiTR,odemefarkiEN,odemefarkiFR) VALUES ('4','1','1','1','1','','','')

INSERT INTO item_kargo(product_id,kargo_id,kargo_priceTR,kargo_priceEN,kargo_priceFR,odemefarkiTR,odemefarkiEN,odemefarkiFR) VALUES ('4','2','2','2','2','','','')

INSERT INTO item_kargo(product_id,kargo_id,kargo_priceTR,kargo_priceEN,kargo_priceFR,odemefarkiTR,odemefarkiEN,odemefarkiFR) VALUES ('4','4','3','3','3','3','3','3')
  • 写回答

1条回答 默认 最新

  • duanpa1898 2013-04-27 10:04
    关注

    If can't you get your error from mysql_error() you can "echo" your data with var_dump(), so you can see how your array is build up. This helps me often to figure out my error in some loops.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 qc代码,修改和添加东西
  • ¥50 Unity的粒子系统使用shadergraph(内置管线)制作的一个顶点偏移shader,但是粒子模型移动时,顶点也会偏移
  • ¥15 如何用python处理excel的数据(极值标准化)
  • ¥15 三向应力状态求剪应力
  • ¥15 jupyter notebook如何添加libGL.so.1库
  • ¥20 easyPoi能否实现下拉多选或者复选框
  • ¥15 网桥在转发帧时,会变帧的源地址和目的地址吗?
  • ¥15 用Multisim设计汽车尾灯控制电路
  • ¥100 求用matlab求解上述微分方程的程序代码
  • ¥15 MAC安装佳能LBP2900驱动的网盘提取码