Updating Values as Zero from Excel Import
<p>I am using the followng code, to import csv into mysql.</p>

<pre class="lang-php prettyprint-override"><code> if($_POST['sform'] == "1")
{
     $fname = $_FILES['upload']['name'];        
     $chk_ext = explode(".",$fname);        
     if(strtolower($chk_ext[1]) == "csv")
     { 
        $filename = $_FILES['upload']['tmp_name'];
        $row = 1;
        if (($handle = fopen($filename, "r")) !== FALSE)
        {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
              {
                $row++;
                $data_entries[] = $data ;
              }
              fclose($handle);
         }
         foreach($data_entries as $line)
         {
              $sql = "INSERT into testposts(ID,UID,title,tags,desc) values('','$data[0]','$data[1]','$data[2]','$data[3]')";
$conn-&gt;execute($sql);
          $conn-&gt;execute($line);
         }
         $msg = "Successfully Imported";
     }
     else
     {
         $error = "Invalid File";
     }   
}
</code></pre>

<p>When I try to update then all values gets updated as 0</p>

<p>my csv file as follow (example)</p>

<pre><code>1,title,tags,send2
</code></pre>

<p>Am not including PID value as it is auto incremented</p>

<p>So I tried with my second variation</p>



<pre><code>if($_POST['sform'] == "1")
{
     $fname = $_FILES['upload']['name'];        
     $chk_ext = explode(".",$fname);        
     if(strtolower($chk_ext[1]) == "csv")
     { 
 $filename = $_FILES['upload']['tmp_name'];
     $handle = fopen($filename, "r");

     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
     {
              $sql = "INSERT into testposts(ID,UID,title,tags,desc) values('','$data[0]','$data[1]','$data[2]','$data[3]')";
          mysql_query($sql) or die(mysql_error());
          //$conn-&gt;execute($sql);
         }
         $msg = "Successfully Imported";
     }
     else
     {
         $error = "Invalid File";
     }   
}
</code></pre>

<p>In my second code, it uploads the value correctly as expected but it inserts twice.</p>

<p>Any help would be much appreciated, Thanks</p>
