title: How to fix php uploads only 1 row of a .csv, .xls, .xlsx files per upload?
body: <p>I want to include excel or csv file upload functionality in my project. I used phpspreadsheet and I used the <code>fgetcsv()</code> function in php but all uploads well but it only picks one(1) record/row in all the file types. Please help!!!</p>
  
  <p>This is my code:</p>
  
  <pre><code>// If the file is uploaded
  if(is_uploaded_file($_FILES['csv_file']['tmp_name'])){
  
      // Open uploaded CSV file with read-only mode
      $csvFile = fopen($_FILES['csv_file']['tmp_name'], 'r');
  
      // Skip the first line
      fgetcsv($csvFile);
  
      //generate voters id
      $set = '123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
      $password = substr(str_shuffle($set), 0, 8);
  
      // Parse data from CSV file line by line
      while(($line = fgetcsv($csvFile)) !== FALSE){
          // Get row data
          $indexnumber   = $line[0];
          $firstname  = $line[1];
          $lastname  = $line[2];
  
          // Check whether member already exists in the database with the same email
          $prevQuery = "SELECT id FROM voters WHERE indexnumber = '".$line[0]."'";
          $prevResult = $conn-&gt;query($prevQuery);
  
          if($prevResult-&gt;num_rows &gt; 0){
              // Update member data in the database
              $conn-&gt;query("UPDATE voters SET firstname = '".$firstname."', laststname = '".$laststname."', password = '".$password."', status = 'Unvoted', WHERE indexnumber = '".$indexnumber."'");
          }else{
              // Insert member data in the database
              $conn-&gt;query("INSERT INTO voters (indexnumber, firstname, lastname, password, status) VALUES ('".$indexnumber."', '".$firstname."', '".$lastname."', '".$password."', 'Unvoted')");
          }
      }
  
      // Close opened CSV file
      fclose($csvFile);
  </code></pre>
  
  <p>If I echo <code>$line</code> i get</p>
  
  <pre><code>8170123 fati abdu 8170124 faiza aliu 8170125 laila abdallah 8170126 lulaby wakil 8170127 fathiya napate 
  </code></pre>