使用php将excel表导入mysql表

时间:2016-10-05 09:16:30

标签: php mysql excel

我想用PHP导入excel表数据到mysql表但我得到这些错误有人请让我从这里...请看看PHP代码只忽略html的东西。

<?php
    include ("connection.php");

    if(isset($_POST["submit"]))
    {
        $file = $_FILES['file']['tmp_name'];
        $handle = fopen($file, "r");
        $c = 0;
        while(($filesop = fgetcsv($handle, 1000, ",")) !== false)
        {
            $name = $filesop[1];
            $email = $filesop[2];

            $sql = mysql_query("INSERT INTO co (name, email) VALUES ('$name','$email')");

            $c = $c + 1;

        }
        fcose($file);

            if($sql){
                echo "You database has imported successfully. You have inserted ". $c ." recoreds";
            }else{
                echo "Sorry! There is some problem.";
            }

    }
?>

this is excel sheet

in database it is showing different format

1 个答案:

答案 0 :(得分:0)

有图书馆excellibrary/php-excel-reader/excel_reader2.phpexcellibrary/SpreadsheetReader.php

您可以使用这些库来读取您的内容并将其转换为数组。 将电子表格数据转换为数组后,可以使用迭代轻松插入数据库。