html - PHP CSV file import does not import data if there's empty value -
i have piece of code here , doesn't import data if there's comma in front of row. means empty value in column code doesn't recognize , therefore doesn't import data @ all. ideas how can fix that? in advance!
<?php include "config.php"; if ($_files[csv][size] > 0) { $file = $_files[csv][tmp_name]; $handle = fopen($file,"r"); { if ($data[0]) { mysql_query("insert norse5_proov (osakond, soetusaasta, it_number, tooteruhm, mudeli_nimetus, sn, riigivara_nr, inventaari_nr, maja, ruum, vastutaja, markus, kasutajanimi) values ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."', '".addslashes($data[3])."', '".addslashes($data[4])."', '".addslashes($data[5])."', '".addslashes($data[6])."', '".addslashes($data[7])."', '".addslashes($data[8])."', '".addslashes($data[9])."', '".addslashes($data[10])."', '".addslashes($data[11])."', '".addslashes($_session['user'])."' ) ") or die(mysql_error()); } } while ($data = fgetcsv($handle,1000,",","'")); header('location:insert.php?success=1'); die; } ?>
you need change
if ($data[0]) {
to
if (!empty($data)) {
basically, doing @ moment checking if there data in first column, , if not ignoring row, if change suggested, check if there data in whole row, , if there import it, otherwise skip.
Comments
Post a Comment