title: Uploading Large CSV File into Mysql Database
body: <p>I want to upload large CSV document into mysql database can anyone help me out, the table consist of 10 fields but i want to upload into only 5 fields of the table without a heading. I want this done with php in the browser</p>
  
  <pre><code>$filename = $_FILES['sel_file']['tmp_name'];
  &lt;?php
      if($_FILES["file"]["type"] != "application/vnd.ms-excel"){
         die("This is not a CSV file.");
      }
      elseif(is_uploaded_file($_FILES['file']['name'])){
       $dbhost = 'localhost';
       $dbuser = 'root';
       $dbpass = '';
       $dbname = 'cbt_software';
       $link = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error        connecting to mysql server');
     mysql_select_db('cbt_software') or die(mysql_error());
     //Process the CSV file
     $handle = fopen($_FILES['file']['name'], "r");
     $data = fgetcsv($handle, 1000, ";"); 
     while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
        $att0 = mysql_real_escape_string($data[0]);
        $att1 = mysql_real_escape_string($data[1]);
        $att2 = mysql_real_escape_string($data[2]);
        $att3 = mysql_real_escape_string($data[3]);
        $att4 = mysql_real_escape_string($data[4]);  
  
        $sql = "INSERT INTO `course_reg` (`coursecode`,`coursename`,`coursedescription`,`coursemaster`,`courselevel`)VALUES     ('$att0','$att1','$att2','$att3','$att4')";
        mysql_query($sql) or die(mysql_error());
     }
     mysql_close($link);
     echo "CSV file successfully imported.";
  }
  else{
     die("You shouldn't be here");
  }
  ?&gt;
  </code></pre>
  
  <p>At first this imported all the field from the csv into just one field in the database and after i tampered with the code it is not recognicing it a s a CSV file.</p>