Home > Article > Backend Development > 导入excel文件时疏失在线求解
导入excel文件时出错在线求解
有个关于导入excel文件的问题求解。。
error_reporting(0);
//导入CSV格式的文件
$connect=mysql_connect("localhost","root","root") or die("could not connect to database");
mysql_select_db("student",$connect) or die (mysql_error());
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $connect);
$fname = $_FILES['MyFile']['name'];
$handle=fopen("$fname","r");
while($data=fgetcsv($handle,10000,","))
{
$q="insert into timetable (cid,week,jieci,name,teacher) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
mysql_query($q) or die (mysql_error());
}
fclose($handle);
$fname = $_FILES['MyFile']['name'];
$do = copy($_FILES['MyFile']['tmp_name'],$fname);
if ($do)
{
echo"导入数据成功
";
} else {
echo "";
}
当我第一次提交之后导入的
excel会在文件夹下面 但是数据库里面没有
我继续提交之后提示:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\x87.\xC76\x90\xF4\x03\x14kl\x8B\xD8\x92\xD0L\xD2\xE4\xEF;v\x16J\xC8\x82i\xA0\xB' at line 1
这该怎么搞?明天要交作业了 求指导。