title: Loading CSV file into mysql database using php
body: <p>I ma struggling to load information from a csv file using PHP and want to save the contents of csv (mobile phone numbers) into mysql database table.The file contents look like this:</p>
  
  <p>CSV file contents ( individual record per single line with no commas)</p>
  
  <pre><code>44762126064    
  447508751    
  4474669756    
  44771466603    
  444584871    
  445574805    
  447455471039    
  44777451345
  447460345819    
  44793342963    
  44734838672    
  44752845528    
  4474537291    
  44779645078
  </code></pre>
  
  <p>I am try to upload csv file using form and submit.The code read csv file and tries to write the content into mysql table.The problem  is that code is returning all the csv records in one array element like this:</p>
  
  <pre><code>Array( 
      [0] =&gt; 44762126064 447508751 4474669756 44771466603 444584871 445574805 447455471039 44777451345 447460345819 44793342963 44734838672 44752845528 4474537291 44779645078 
  );
  </code></pre>
  
  <p>and inserting the whole array as one record rather one mobile number per row in mysql table.</p>
  
  <p>The code :</p>
  
  <pre><code>if (isset($_POST['submit'])) {
      if (is_uploaded_file($_FILES['filename']['tmp_name'])) {
          echo "&lt;h1&gt;" . "File ". $_FILES['filename']['name'] ." uploaded successfully." . "&lt;/h1&gt;";
      echo "&lt;h2&gt;Displaying contents:&lt;/h2&gt;";
      #    readfile($_FILES['filename']['tmp_name']);
  }
  
  //Import uploaded file to Database
  $handle = fopen($_FILES['filename']['tmp_name'], "r");
  
  while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
  
             $import="INSERT into mobilecsv(phoneMobile,status) values('$data[0]',0)";
  
      mysql_query($import) or die(mysql_error());
  }
  
  fclose($handle);
  
  print "Import done";
  
  }
  </code></pre>
  
  <p>I have tried <code>explode()</code>, <code>array_slice()</code> etc but none of them helped me to split this array contents to save them as individual records/phone numbers in mysql database.</p>
  
  <p>How can i split individual contents of first array element(as in my case) to save them as separate individual records as appearing in my CSV? I am a new programmer and would appreciate your help in this regard.Thanks </p>