title: PHPspreadsheet extracting and importing data from Excel to MYSQL. Implode function warning error
body: <p>I've been trying to extract data from the excel file and import it to MYSQL using PHPspreadsheet.
  This is the excel file.</p>
  <p><a href="https://i.stack.imgur.com/5CJFj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5CJFj.png" alt="enter image description here" /></a></p>
  <p>My current code works but it only extracted and imported this 3rd row to my database,
  <a href="https://i.stack.imgur.com/Azo2M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Azo2M.png" alt="enter image description here" /></a></p>
  <p>and ignores the remaining row from the excel.</p>
  <p>This is the code,</p>
  <pre><code>&lt;?php
  require 'vendor/autoload.php';
  include 'connect.php';
  
  if (isset($_POST[&quot;submit&quot;])) {
      if($_FILES[&quot;uploadfile&quot;][&quot;name&quot;] != '') {
          $allowed_extension = array('xls', 'csv', 'xlsx');
          $file_array = explode('.', $_FILES[&quot;uploadfile&quot;][&quot;name&quot;]);
          $file_extension = end($file_array);
  
          if(in_array($file_extension, $allowed_extension)) {
              $file_name = 'moved_files/'.time(). '.' . $file_extension;
              move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file_name);
              $file_type = \PhpOffice\PhpSpreadsheet\IOFactory::identify($file_name);
              $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($file_type);
              $reader-&gt;setReadDataOnly(TRUE); $reader-&gt;setReadEmptyCells(FALSE);
              $spreadsheet = $reader-&gt;load($file_name);
              unlink($file_name);
              $data = $spreadsheet-&gt;getActiveSheet()-&gt;toArray();
  
              $sql = '';
              for ($row = 2; $row &lt;= count($data); $row++) {
                  $val = &quot;'&quot; . implode(&quot;','&quot;, $data[$row]) . &quot;'&quot;;
                  echo $val;
                  $sql = &quot;INSERT INTO spreadsheet (course_name, program, campus, credits, number_streams, tutor, monday, 
                          tuesday, wednesday, thursday, friday)
                          VALUES ($val);&quot;;
  
                  if($conn-&gt;query($sql) === TRUE) {
                      echo &quot;Data $row inserted successfully&quot;.&quot;&lt;br&gt;&quot;;
                  }
                  else {
                      echo &quot;Error: &quot; . $sql . &quot;&lt;br&gt;&quot; . $conn-&gt;error;
                  }
                  $conn-&gt;close();
              }
            }
          } 
  ?&gt;
  </code></pre>
  <p>However, I got an error that says, Undefined offset in this line of code <code>$val = &quot;'&quot; . implode(&quot;','&quot;, $data[$row]) . &quot;'&quot;;</code></p>
  <p>and an implode() Warning. I've researched and some of the few solutions I've encountered are making sure that the implode() must take in an array value. But the <code>$data</code> has already been converted toArray().
  Any ideas what I'm missing? I'm a beginner in using PHP and PHPspreadsheet so any help or ideas would be much appreciated. Thanks a lot.</p>