Import CSV file into mysql using php

Submitted by vishaalmandge on
Hi friends, I have following code for import csv file data into mysql, but it won't import the data in database, can any body pls help me for this ? my code as follows
  1. <?php
  2.  
  3.         mysql_connect("localhost", "username", "password") or die(mysql_error());
  4.        
  5.         mysql_select_db("test") or die(mysql_error());
  6.  
  7.  
  8. if(isset($_POST['submit']))
  9.    {
  10.      $filename=$_POST['filename'];
  11.      $handle = fopen("$filename", "r");
  12.      while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
  13.      {
  14.    
  15.        $import="INSERT INTO data_status(Date,Campaign_name,Email_id,Mailing_platform,Email_status) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]')";
  16.        mysql_query($import) or die(mysql_error());
  17.      }
  18.      fclose($handle);
  19.      print "Import done";
  20.  
  21.    }
  22.    else
  23.    {
  24.  
  25.       print "There is nothing to do, click here to go back home";
  26.  
  27. }
  28.    
  29. ?>