php把excel导入到mysql中乱码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>数据导入工程</title>
</head>
<body><?php
$fname = $_FILES['MyFile']['name'];
$do = copy($_FILES['MyFile']['tmp_name'],$fname);
if ($do)
{
echo"导入数据成功<br>";
} else {
echo "";
}
?>
<form ENCTYPE="multipart/form-data" ACTION="<?php echo"".$PHP_SELF.""; ?>" METHOD="POST">
<p>导入CVS数据 <input NAME="MyFile" TYPE="file"> <input VALUE="提交" TYPE="submit">
</p>
</form>
<?
error_reporting(0);
//导入CSV格式的文件
$connect=mysql_connect("localhost","root","") or die("could not connect to database");
mysql_select_db("zngift",$connect) or die (mysql_error());
$fname = $_FILES['MyFile']['name'];
$handle=fopen("$fname","r");
$mydate = date("Y-m-d H:i:s");
while($data=fgetcsv($handle,1000,","))
{
$q="insert into hu_msg (cateid,subject,author,postdate,hits,taxis,thumb,ifcheck,mark,brandid,number,m_price,s_price,promotions) values ('$data[0]','$data[1]','admin','$mydate','$data[4]',0,'$data[5]',1,'$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','更多优惠请致电')";
mysql_query($q) or die (mysql_error());
}
fclose($handle);
?>
</body>
</html>
那是从网上找的代码,已经能写进数据库了,可是中文全是乱码啊?怎么解决?
追问:我纳闷了。从cvs里面的数据能够正常输出到页面。但是,写进数据库后,就乱码了。