hello dr..........
i m trying to store a text file into database below format of text file
i hv text file like this:
0100102001110271 0409141151I1476201
0100102001110125 0409141351O1476301
0100101300000030 0409141630O1476401
0100102001110271 0409141631O1476501
0100102001110126 0409141632O1476601
how can store it into my database table att0310
my table fileds:
cardno date time IO(in-out) and serial no
0100102001110271 this is card no
040914 for date
1151 for time
I for IO
1476201 for serial no
plz help me out
till date data is inserted correctly into database but next data not stored into database. because of there is no space b/w those digits .... hw can i store that into database.... i tried so many times......... i used fopen function to read file character by character but i only display dat on browser not into database .. plz help me out.........
<html>
<?
$con=mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('test',$con);
//(1) Read the text file into a variable
$file=fopen("ATND.txt","r") or exit("Unable to open file!");
//(2) Then we can get rid of the tabs in there:
$output = str_replace("\t"," ", $file);
//(3) Then we explode it at every line break
$output = explode("\n", $output);
//(4) Then we loop through all the array elements and explode them again and insert them into mysql
foreach($output as $var)
{
$tmp = explode(" ", $var);
//$ecode = $tmp[0];
$ecardno = $tmp[0];
$atdate = $tmp[1];
$attime = $tmp[2];
$IO = $tmp[3];
$scode = $tmp[4];
$sql = "INSERT INTO att SET ecardno='$ecardno',atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno'";
mysql_query($sql);
}
echo "Done!";
mysql_close($con);
?>
</html>