Php 将文本文件内爆到数据库中
我正在尝试将文本文件内爆到mysql数据库中。我有姓名、代码、邮件id、职务和薪水栏。我的密码是:Php 将文本文件内爆到数据库中,php,mysql,Php,Mysql,我正在尝试将文本文件内爆到mysql数据库中。我有姓名、代码、邮件id、职务和薪水栏。我的密码是: <?php include("includes/config.php"); if ($_POST['frmSubmit']) { $file = $_FILES['frmUpload']['tmp_name']; // Get Temporary filename if ($file) { $ha
<?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';
}
}
?>
但我有错误列不匹配,我不知道我缺少什么。请帮助我。var\u dumpcount$strTableColumn;->可能不止4行?我的文本数据是:姓名|代码|邮件|名称|薪水|哈里| 100|hari@gmail.com|学员| 6000\t Syed | 101|syed@gmail.com|培训生| 6000\t拉贾| 102|raja@gmail.com|培训生| 6000\tvaru dumpcount$strTableColumn;我应用了代码var_dumpcount$strTableColumn;它以int1 int1 int1 int1 int1的形式给出输出。您的错误是:检查count$strTableColumn是否为4,但它是否为1,这样您就得到了该错误