title: PHP: Column count doesn't match when importing CSV file with empty cells/columns
body: <p>I have a code that will allow users to import/insert data into database from the CSV file. the problem is that if there is an empty columns or cells from the CSV file, it will display an error telling me that the <strong>column count doesn't match value count at row 1</strong>. I tried to assign a value in the empty cells/columns of the CSV file and it successfully uploaded. How can I allow the users to upload a CSV file even if there's an empty columns/cells? Below is my code.</p>
  
  <pre><code>            if ($handle) {
                  $counter = 0;
                  $sql ="INSERT IGNORE INTO bill_of_materials(allotment_code, category_name, activity, quantity, unit, description, end_unit_quantity, unit_cost, regular_labor_cost, end_unit_labor_cost, type, batch) VALUES";
  
                  while (($line = fgets($handle)) !== false) {
  
                      $sql .= "('".implode("', '", explode("|", addslashes(str_replace('"', '', $line))))."'),";
                      $counter++;
                  }
  
                  $sql = substr($sql, 0, strlen($sql) - 1);
  
                   if (mysqli_query($new_conn, $sql) === TRUE) {
  
                      $message = 1;
  
                  } else {
  
                      echo mysqli_error($new_conn);
                  }
                  fclose($handle);
  </code></pre>
  
  <p>here is my table:
  <a href="https://i.stack.imgur.com/zyKhd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zyKhd.png" alt="my table"></a></p>
  
  <p>and here's the csv file:
  <a href="https://i.stack.imgur.com/ieSj6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ieSj6.png" alt="csv file"></a></p>