doufangmu9087 2018-03-12 21:34
浏览 172

使用while循环将多个数据插入到mysql数据库表中

the script is supposed to insert multiple data into the database but for some reason its inserting only the first data. This is the aspect of my code that gives the issue.

$pledge_amount = "400";
$getDonors = mysqli_query($connection, "SELECT * FROM `highck39_earn`.`users` WHERE `tomerge` = '2' AND `role`='0' AND `status` = '0'  AND `username` != '$username' ORDER BY `reward_date` ASC LIMIT 0, 2"); 

    $i=0;
    while($resultObj = mysqli_fetch_assoc($getDonors)){

          $rewardBal = $resultObj['reward_balance'];
          $ind_amt = $pledge_amount/2;

         $do_donation = mysqli_query($connection, "INSERT INTO `highck39_earn`.`donations` (`id`, `transaction_id`, `sender`, `sender_name`, `sender_number`, `sender_momo_number`, `receiver`, `receiver_name`, `receiver_number`, `receiver_momo_number`, `amount`, `date`, `status`) VALUES (NULL, '{$transcode}', '{$username}', '{$fullname}', '{$phone}', '{$momo}', '{$resultObj['username']}', '{$resultObj['fullname']}', '{$resultObj['phone']}', '{$resultObj['momo']}', '{$ind_amt}', '{$pledge_date}', '1')");

          $i++;
          echo $i;
          echo $resultObj['fullname']. ' - '. $ind_amt.'<br>';    
          // if($cnt % 2 == 0) echo "<br>";


          // $data2 = array("fullname" => $fullname, "receiver"=>$resultObj['fullname']);
            //echo json_encode($data2,JSON_FORCE_OBJECT); 
    }
  • 写回答

1条回答 默认 最新

  • doucongmishang2385 2018-03-12 22:59
    关注

    Do you have any sql error in your log when you try to do the insert ?

    You can check if the insert worked correctly with something like :

    if (mysqli_query($connection, "INSERT INTO...") === TRUE) {
        printf("Insert ok");
    }
    

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值