want to insert record from txt file as well as from another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • puneetmca
    New Member
    • Jan 2010
    • 15

    want to insert record from txt file as well as from another table

    hi .........
    i have two tables emp_company and at0310.
    at0310 table having fields: ecardno,atdate, attime,IO,seria lno,cardrd and ecode.
    into my text file ecardno,atdate, time,IO,serialn o,cardrd record available but ecode not comes from there. in my emp_compnay i have fields like ecode,ecardno,e tc . i want in my at0310 table ecode comes from emp_company and only those ecode should be stored into at0310
    that matches with ecard with text file.... can you tell me any query .....
    according to me select and insert needed but i cant place them in working order
    plz help me out waiting for reply
    thank you for taking the time to help me out!
    [code=php]
    <html>
    <?php
    $con=mysql_conn ect("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);
    $ecode=$_POST['ecode'];
    //$sql = "INSERT INTO at0210 SET ecardno='$ecard no', atdate='$atdate ',attime='$atti me',IO='$IO',se rialno='$serial no',ecode='$eco de'
    //select ecode from emp_company where ecardno.emp_com pany=ecardno.at 0310";
    $sql = mysql_query("IN SERT INTO at0310 ('$ecardno', '$atdate','$att ime','$IO','$se rialno','$cardr d'") ("SELECT ecode FROM emp_company WHERE ecode = '$_POST[ecardno]'")");
    mysql_query($sq l);
    }
    echo "Done!";
    ?>
    [/code]
Working...