Home > Backend Development > PHP Tutorial > 导入excel文件时出错在线求解

导入excel文件时出错在线求解

WBOY
Release: 2016-06-23 14:24:39
Original
1595 people have browsed it

有个关于导入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
这该怎么搞?明天要交作业了 求指导。


回复讨论(解决方案)

echo $q; 贴出结果看看

"\x87.\xC76\x90\xF4\x03\x14kl\x8B\xD8\x92\xD0L\xD2\xE4\xEF;v\x16J\xC8\x82i\xA0\xB"
显然不是 utf-8 编码的数据

csv文件另存为UTF-8编码的文档。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template