bangdiem.csv
[caption id="" align="alignnone" width="318" caption="http://img705.imageshack.us/img705/8397/bangdiem.jpg"][/caption]
mysql
b2: tạo trang demo.php như sau
<!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>Trung Tam Nhat Nghe</title>
</head>
<body>
<?
$db = mysql_connect("localhost", "root", "root") or die("Could not connect.");
if(!$db)
die("no db");
if(!mysql_select_db("quanlydiem",$db))
die("No database selected.");
if(isset($_GET['submit']))
{
$filename=$_GET['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
{
$import="INSERT into bangdiem(hoten,toan,van) values('$data[0]',$data[1],$data[2])";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='demo.php' method='get'>";
print "Type file name to import:<br>";
print "<input type='file' name='filename' size='20' width=40 value='bangdiem.csv'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>
</body>
</html>
kết quả