我正在使用循环将CSV中的每一行导入数据库。它工作正常,除了CSV中有一行得到错误:
列数与第1行的值计数不匹配
我查看了这行,似乎没有注意到它和其他行之间有任何区别,但是如果我删除了这一行,一切正常,它会导入整个文件。
这是循环:
$filters = ["batches", "batches-2"];
// Import the SKU filters file First
foreach($filters as $filter) {
if(!empty($location = $_FILES[$filter]['tmp_name'])) { // For each file, check if it's empty
$file = fopen($location, "r");
$filearray = fgetcsv($file);
while(!feof($file)) { // For each file uploaded:
$filearray = fgetcsv($file);
$batch = $filearray['1'];
if(!empty($batch)) {
$skusearchquery = mysqli_real_escape_string($connect, $filearray['0']);
$fees = mysqli_real_escape_string($connect, $filearray['2']);
$costofgoods = mysqli_real_escape_string($connect, $filearray['3']);
$number = mysqli_real_escape_string($connect, $filearray['4']);
$lister = mysqli_real_escape_string($connect, $filearray['5']);
$listerfee = mysqli_real_escape_string($connect, $filearray['6']);
$tier1a = mysqli_real_escape_string($connect, $filearray['7']);
$tier1asplit = mysqli_real_escape_string($connect, $filearray['8']);
$tier1b = mysqli_real_escape_string($connect, $filearray['9']);
$tier1bsplit = mysqli_real_escape_string($connect, $filearray['10']);
$tier1c = mysqli_real_escape_string($connect, $filearray['11']);
$tier1csplit = mysqli_real_escape_string($connect, $filearray['12']);
$tier1d = mysqli_real_escape_string($connect, $filearray['13']);
$tier1dsplit = mysqli_real_escape_string($connect, $filearray['14']);
$tier1e = mysqli_real_escape_string($connect, $filearray['15']);
$tier1esplit = mysqli_real_escape_string($connect, $filearray['16']);
$tier2 = mysqli_real_escape_string($connect, $filearray['17']);
$tier2split = mysqli_real_escape_string($connect, $filearray['18']);
$tier3a = mysqli_real_escape_string($connect, $filearray['19']);
$tier3asplit = mysqli_real_escape_string($connect, $filearray['20']);
$tier3b = mysqli_real_escape_string($connect, $filearray['21']);
$tier3bsplit = mysqli_real_escape_string($connect, $filearray['22']);
$tier3c = mysqli_real_escape_string($connect, $filearray['23']);
$tier3csplit = mysqli_real_escape_string($connect, $filearray['24']);
$tier3d = mysqli_real_escape_string($connect, $filearray['25']);
$tier3dsplit = mysqli_real_escape_string($connect, $filearray['26']);
$tier3e = mysqli_real_escape_string($connect, $filearray['27']);
$tier3esplit = mysqli_real_escape_string($connect, $filearray['28']);
$investorrate = mysqli_real_escape_string($connect, $filearray['29']);
$investora = mysqli_real_escape_string($connect, $filearray['30']);
$investorasplit = mysqli_real_escape_string($connect, $filearray['31']);
$investorb = mysqli_real_escape_string($connect, $filearray['32']);
$investorbsplit = mysqli_real_escape_string($connect, $filearray['33']);
$investorc = mysqli_real_escape_string($connect, $filearray['34']);
$investorcsplit = mysqli_real_escape_string($connect, $filearray['35']);
$investord = mysqli_real_escape_string($connect, $filearray['36']);
$investordsplit = mysqli_real_escape_string($connect, $filearray['37']);
$investore = mysqli_real_escape_string($connect, $filearray['38']);
$investoresplit = mysqli_real_escape_string($connect, $filearray['39']);
$investorf = mysqli_real_escape_string($connect, $filearray['40']);
$investorfsplit = mysqli_real_escape_string($connect, $filearray['41']);
$query = mysqli_query($connect, "SELECT * FROM skusearch WHERE skusearchquery='$skusearchquery'"); // Select any rows that match the skusearchquery.
if(mysqli_num_rows($query) > 0) { // do this to rows already in the databse that match this query:
} else {
$insert = mysqli_query ($connect, "INSERT INTO skusearch (skusearchquery, batch, costofgoods, number, fees, lister, listerfee, tier1a, tier1asplit, tier1b, tier1bsplit, tier1c, tier1csplit, tier1d, tier1dsplit, tier1e, tier1esplit, tier2, tier2split, tier3a, tier3asplit, tier3b, tier3bsplit, tier3c, tier3csplit, tier3d, tier3dsplit, tier3e, tier3esplit, investorrate, investora, investorasplit, investorb, investorbsplit, investorc, investorcsplit, investord, investordsplit, investore, investoresplit, investorf, investorfsplit) VALUES ('$skusearchquery', '$batch', $costofgoods, $number, $fees, '$lister', '$listerfee', '$tier1a', '$tier1asplit', '$tier1b', '$tier1bsplit', '$tier1c', '$tier1csplit', '$tier1d', '$tier1dsplit', '$tier1e', '$tier1esplit', '$tier2', '$tier2split', '$tier3a', '$tier3asplit', '$tier3b', '$tier3bsplit', '$tier3c', '$tier3csplit', '$tier3d', '$tier3dsplit', '$tier3e', '$tier3esplit', '$investorrate', '$investora', '$investorasplit', '$investorb', '$investorbsplit', '$investorc', '$investorcsplit', '$investord', '$investordsplit', '$investore', '$investoresplit', '$investorf', '$investorfsplit')") or die(mysqli_error($connect));
}
}
}
}
}
And here is the file. 第6行,以“JGK”开头的行是获取此错误的行。如果我删除问题行,它导入之前的每隔一行和导入后的行都没有问题。有什么想法吗?