dskm94301
dskm94301
2019-04-12 05:06

使用php将excel数据导入数据库表

  • excel
  • php
  • mysql

problem is in my excel 369 rows are there. when I echo/print that data it showing correct but when I am inserting same data in DB table in inserted only 18 - 30 records.

if (isset($_POST['Submit'])) {
    $file = $_FILES['csv_file']['tmp_name'];
    $handle = fopen($file, "r");
    if ($file == NULL) {
    error(_('Please select a file to import'));
    redirect(page_link_to('excel_data_upload'));
    }else {
        $conn = connect();
        while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
        {
            $num3 = $filesop[3];
            $num8 = $filesop[8];
            $num9 = $filesop[9];
            $num20 = $filesop[20];
            if($num3!='ExpiryDate' &&$num8!='VCNO' &&$num20!='TotalB2CAmount' && $num9 !='STBNO'){

                $insertAgent =  mysqli_query($conn, "INSERT INTO `upload_billing_data` 
                (`vc_number`,`stb_number`,`operator_id`,`expiry_date`,`monthly_bill_amount`) 
                VALUES ('$num8','$num9',140,'$num3','$num20')");

                if($insertAgent)
                {
                    echo 'succss';
                }else{
                    echo 'error';
                }

            }  
        }
        close($conn);

    }
}

I am fetching from the excel data. I want to insert all records

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐

换一换