我想用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.";
}
}
?>
答案 0 :(得分:0)
有图书馆excellibrary/php-excel-reader/excel_reader2.php
和excellibrary/SpreadsheetReader.php
您可以使用这些库来读取您的内容并将其转换为数组。 将电子表格数据转换为数组后,可以使用迭代轻松插入数据库。