error_reporting (0);//import CSV format file $connect =mysql_connect ("localhost", "root", "") or Die ("could not connect to database"); mysql_select_db ("Gklqtzcx", $connect) or Die (Mysql_error ()); mysql_query ("Set names ' GBK '"); $fname = $_files[' myfile ' [' name ']; $handle =fopen ("$fname", "R"); while ($data =fgetcsv ($handle, 10000, ",")) { $q = "INSERT Into records (Name,classes,a_time,college,notify,receiver,r_time,handler) VALUES (' $data [1] ', ' $data [2] ', ' $data [3] ', ' $data [4] ', ' $data [5] ', ' $data [6] ', ' $data [7] ', ' $data [8] ']; mysql_query ($q) or Die (Mysql_error ()); } Fclose ($handle); echo "<meta http-equiv=" "Refresh" content= "1;url=list.php" >1 seconds into the list page, please wait a moment. " ?> <form enctype= "Multipart/form-data" action= "<?php echo" "". $_server["Php_self"]. ""; ?> "method=" POST "> <p> Import CVS data <input name= "myfile" type= "file" > <input value= "submitted" type= "Submit" > </p> </form> |