How to Import Excel file into mysql Database from PHP

后端 未结 2 867
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 05:44

Lets say, i want to import/upload excel file to mysql from PHP

My HTML is like below

2条回答
  •  后悔当初
    2021-01-31 06:14

    For >= 2nd row values insert into table-

    $file = fopen($filename, "r");
    //$sql_data = "SELECT * FROM prod_list_1 ";
    
    $count = 0;                                         // add this line
    while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
    {
        //print_r($emapData);
        //exit();
        $count++;                                      // add this line
    
        if($count>1){                                  // add this line
          $sql = "INSERT into prod_list_1(p_bench,p_name,p_price,p_reason) values ('$emapData[0]','$emapData[1]','$emapData[2]','$emapData[3]')";
          mysql_query($sql);
        }                                              // add this line
    }
    

提交回复
热议问题