我试图将文本文件内爆到mysql数据库中。我有列名称,代码,邮件ID,名称和&薪水。我的代码是:
<?php
include("includes/config.php");
if ($_POST['frmSubmit']) {
$file = $_FILES['frmUpload']['tmp_name']; // Get Temporary filename
if ($file) {
$handle = fopen($file,"r"); // Open the file and read
while($strBookData = fgets($handle, 4096)) {
$strData[] = $strBookData;
$strData1 = str_replace(array("\r\n", "\r", "\n"), "", $strData);
$rows = explode('\t', implode($strData1));
$strTableColumn = count($rows);
}
$strDatas = array();
foreach ($rows as $row){
if(!empty( $row )){
$strDatas[] = explode('|', $row);
}
}
if ($strDatas) {
$strInsertRecords = 0;
$strDuplicationRecords = 0;
if ($strTableColumn == 4) {
for($k=1; $k<count($strDatas); $k++) { //$k=1 is initialized because $k[0] is a header field array.
$strStatus = doCheckDuplication($strDatas[$k]['2']);
if ($strStatus == 0) {
doInsertEmployeeDetails($strDatas[$k]['0'], $strDatas[$k]['1'], $strDatas[$k]['2'], $strDatas[$k]['3'], $strDatas[$k]['4']);
$strInsertRecords++; // To Get Inserted Records Count.
} else {
$strDuplicationRecords++; // To Get Duplication Records Count.
}
}
if (count($strDatas)-1 == $strInsertRecords) {
$strMsg = 'Employee record(s) inserted successfully!';
$strClass = 'Success';
}
if (count($strDatas)-1 != $strInsertRecords) {
$strMsg = 'Employee record(s) inserted successfully but some of record(s) are already exists.!';
$strClass = 'Error';
}
if (count($strDatas)-1 == $strDuplicationRecords) {
$strMsg = 'Employee record(s) are already exists.!';
$strClass = 'Error';
}
} else {
$strMsg = 'Column mis-match, Please verify the file.';
$strClass = 'Error';
}
}
} else {
$strMsg = 'Please upload a valid file.';
$strClass = 'Error';
}
}
?>
但我的错误列不匹配,我不知道我错过了什么。请帮帮我。