0) { $file = fopen($filename, "r"); while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE) { //It wiil insert a row to our subject table from our csv file` $sql = "INSERT into enrichment (`Subject`, `Level`, `Date`,`Time`,`Fee`,`Registration`) values('$emapData[1]','$emapData[2]','$emapData[3]','$emapData[4]','$emapData[5]','$emapData[6]')"; //we are using mysql_query function. it returns a resource on true else False on error $result = mysql_query( $sql, $conn ); if(! $result ) { echo ""; exit; } } fclose($file); //throws a message if data successfully imported to mysql database from excel file echo ""; exit; //close of connection mysql_close($conn); } } ?>