我上傳csv文件在數據庫中它已經完成,但是當我上傳csv文件並顯示數據表比上傳表中多一行。 像我上傳10個數據,但在數據表中插入11行。上傳數據庫中的csv文件,但最後提交添加一個數據空白
// path where your CSV file is located
define('csvfile/',
'plivo/dialer/csvfile/');
// Name of your CSV file
$csv_file = $target_dir . "$file";
if (($handle = fopen($csv_file,
"r")) !== FALSE) {
fgetcsv($handle);
while (($data = fgetcsv($handle,
1000,
",")) !== FALSE) {
$num = count($data);
for ($c = 0;
$c < $num;
$c++) {
$col[$c] = $data[$c];
}
echo '<br>'. $col1 = $col[0];
echo 'data'.$col1.'<br>';
if($col1 != ' ' || $col1 != NULL){
// SQL Query to insert data into DataBase
$query = "INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('$caller_id','" . $col1 . "','$play_url','$row_id')";
print_r("INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('$caller_id','" . $col1 . "','$play_url','$row_id')");
$s = mysql_query($query);
if ($s) {
echo 'pass';
header("location:dashboard.php");
} else {
echo 'fail<br>';
}
}
}
fclose($handle);
}
當我打印查詢顯示
1data1
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','1','www.test.com','15')
2data2
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','2','www.test.com','15')
3data3
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','3','www.test.com','15')
4data4
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','4','www.test.com','15')
5data5
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','5','www.test.com','15')
data
INSERT INTO callblast(`callerid`, `phoneno`, `playurl`,`campaignid`) VALUES('9988776655','','www.test.com','15')
最後的數據是這樣的添加
是什麼問題,更多的行添加數據庫。
請幫忙。
謝謝。
添加您嘗試上傳的文件 – sujivasagam