How to Import Excel file into mysql Database from PHP

后端 未结 2 857
伪装坚强ぢ
伪装坚强ぢ 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
    }
    
    0 讨论(0)
  • 2021-01-31 06:33

    You are probably having a problem with the sort of CSV file that you have.

    Open the CSV file with a text editor, check that all the separations are done with the comma, and not semicolon and try the script again. It should work fine.

    0 讨论(0)
提交回复
热议问题