hi guys

m new to this forum ..........
i have emp_company table having field ecode, ecardno etc
and another table is at0310
the fields of this table are
ecardno, date , time, IO, serialno , cardrd and ecode
the data inserted into at0310 table from text file except ecode.........
i want ecode insert in at0310 table from emp_company with where condition that is
emp_company.ecardno=at0310.ecardno

plz help me
thanx in advance

<html>
<?php
$con=mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db('master',$con);
//(1) Read the text file into a variable
$file = "ATND.txt";
$fp = fopen($file, "r");
$data = fread($fp, filesize($file));
fclose($fp);
//(2) Then we can get rid of the tabs in there:
$output = str_replace("\t"," ", $data);
//(3) Then we explode it at every line break
$output = explode("\n", $output);
foreach($output as $var)
{
$tmp = explode(" ", $var);
$ecardno = $tmp[0];
$cluster = $tmp[1];
$atdate = substr($tmp[1],0,6);
$attime = substr($tmp[1],6,4);
$IO = substr($tmp[1],10,1);
$serialno = substr($tmp[1],11,5);
$cardrd = substr($tmp[1],16);
$sql = "INSERT INTO at0310 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',cardrd='$cardrd' select ecode from emp_company where emp_company.ecardno=at0310.ecardno into at0310";


mysql_query($sql);
}
echo "Done!";
?>

I am sorry, but i am not able to understand your question. Can you explain a bit more ?

i mean i have a text file that contains info about cardno,date,time,IO,serialno,cardrd....... that values stores into database table at0310 but in at0310 table ecode also one field that remains empty......when i inserted record from text file all records inserted except ecode......... now i want ecardno should match with emp_company's ecardno and corresponding that no ecode inserted into my at0310 table ........ can you tell me any query that provide me dis facility ..........

waiting for your reply

In your code,

$sql = "INSERT INTO at0310 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',cardrd='$cardrd' select ecode from emp_company where emp_company.ecardno=at0310.ecardno into at0310";

I think the last two words are creating problem.... try removing

into at0310

from the end

I hope that works
Cheers.....!!

I used your idea avinash
but not work......... nothing inserted into database......