Add records from csv
Posted: Tue Jul 04, 2006 12:30 am
Hi i am using the following code to import records from a csv file into mysql
This code inports the data into the database but there is a minor glitch
The tab delimited data is set like this
Date orderno quantity team amount
When the print_r($arr) is executed it shows the data as it is
eg: 20-06-06 5585 50 TeamA 25000
But when the data is added into the database its added's a number 20 before the date and the data is stored like this
2020-06-06 5585 50 TeamA 25000
Can anyone throw light on why this is happening?
Code: Select all
connect_db();
$fname = $_FILES['userfile'];
$fcontents = file ('./Productivity.txt');
//Displays Data from file
echo "<pre>";
print_r($arr);
echo "</pre>";
for($i=0; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i], '\t');
$arr = explode("\t", $line);
$sql = "insert into qcheck (qdate, empno, ename, jobno, activity, chapter, pages, time, dataerr, tagerr)values ('".implode("','", $arr) ."')";
$result = mysql_query ($sql) or die ("Query failed");
}The tab delimited data is set like this
Date orderno quantity team amount
When the print_r($arr) is executed it shows the data as it is
eg: 20-06-06 5585 50 TeamA 25000
But when the data is added into the database its added's a number 20 before the date and the data is stored like this
2020-06-06 5585 50 TeamA 25000
Can anyone throw light on why this is happening?