Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hard to say definitively with your code as it is presented &amp; without seeing the original data, but I believe simply setting a conditional that checks <code>$data</code> is enough to prevent the issue you are seeing:</p> <p>So this line:</p> <pre><code>if ($count) //skip first line of the CSV file { </code></pre> <p>Changes to this:</p> <pre><code>if ($count &amp;&amp; !empty($data)) //skip first line of the CSV file { </code></pre> <p>And here is your code adjusted and indents cleaned up for readability. <strong>EDIT</strong> And I have edited it so there is now a <code>$SUCCESS_SUBMIT</code> variable. That way if the submission is successful &amp; that is <code>true</code> or <code>false</code> you can act on it.</p> <pre><code> include("conection.php"); //Connect to Database $SUCCESS_SUBMIT = false; if (isset($_POST['submit'])) { if (is_uploaded_file($_FILES['filename']['tmp_name'])) { echo "&lt;br&gt;&lt;center&gt;&lt;p&gt;" . " ". $_FILES['filename']['name'] ." " . "&lt;/p&gt;&lt;/center&gt;"; } //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $count = 0; //skip first line of the CSV file while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) { if ($count &amp;&amp; !empty($data)) //skip first line of the CSV file { $import = "INSERT into PAX (name,surname,group) VALUES('$data[0]','$data[1]','$data[2]')"; mysql_query($import) or die(mysql_error()); $SUCCESS_SUBMIT = true; } $count++; } fclose($handle); } if ($SUCCESS_SUBMIT) { print "&lt;br&gt;&lt;center&gt;&lt;p&gt;UPLOADED &lt;/p&gt;&lt;/center&gt; "; print "&lt;br&gt; "; print "&lt;center&gt;&lt;a href='index.php'&gt;&lt;button&gt;HOME&lt;/button&lt;/a&gt;&lt;/center&gt; "; } else { print "&lt;center&gt;&lt;br&gt;&lt;p&gt;&lt;b&gt;UPLOAD&lt;/b&gt; &lt;/p&gt;\n"; print "&lt;center&gt;&lt;br&gt;Select the file for Upload \n"; print "&lt;form enctype='multipart/form-data' action='upload.php' method='post'&gt;"; print "&lt;center&gt;&lt;input size='50' type='file' name='filename'&gt;&lt;br /&gt;\n"; print "&lt;br&gt;"; print "&lt;input type='submit' name='submit' value='UPLOAD'&gt;&lt;/form&gt;"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload