473,503 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

15 New Member
hi .........
i have two tables emp_company and at0310.
at0310 table having fields: ecardno,atdate,attime,IO,serialno,cardrd and ecode.
into my text file ecardno,atdate,time,IO,serialno,cardrd record available but ecode not comes from there. in my emp_compnay i have fields like ecode,ecardno,etc . 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!
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <?php
  3. $con=mysql_connect("localhost","root","root");
  4. if (!$con)
  5. {
  6. die('Could not connect: ' . mysql_error());
  7. }
  8. mysql_select_db('master',$con);
  9. //(1) Read the text file into a variable
  10. $file = "ATND.txt";
  11. $fp = fopen($file, "r");
  12. $data = fread($fp, filesize($file));
  13. fclose($fp);
  14. //(2) Then we can get rid of the tabs in there:
  15. $output = str_replace("\t"," ", $data);
  16. //(3) Then we explode it at every line break
  17. $output = explode("\n", $output);
  18. foreach($output as $var) {
  19. $tmp = explode(" ", $var);
  20. $ecardno = $tmp[0];
  21. $cluster = $tmp[1];
  22. $atdate = substr($tmp[1],0,6);
  23. $attime = substr($tmp[1],6,4);
  24. $IO = substr($tmp[1],10,1);
  25. $serialno = substr($tmp[1],11,5);
  26. $cardrd = substr($tmp[1],16);
  27. $ecode=$_POST['ecode'];
  28. //$sql = "INSERT INTO at0210 SET ecardno='$ecardno', atdate='$atdate',attime='$attime',IO='$IO',serialno='$serialno',ecode='$ecode'
  29. //select ecode from emp_company where ecardno.emp_company=ecardno.at0310";
  30. $sql = mysql_query("INSERT INTO at0310 ('$ecardno', '$atdate','$attime','$IO','$serialno','$cardrd'") ("SELECT ecode FROM emp_company WHERE ecode = '$_POST[ecardno]'")");
  31. mysql_query($sql);
  32. }
  33. echo "Done!";
  34. ?>
  35.  
Feb 24 '10 #1
0 1064

Sign in to post your reply or Sign up for a free account.

Similar topics

15
7363
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
1
8728
by: PT | last post by:
I got a problem. And thats..... First of all, I got these three tables. ------------------- ------------------ ---------------------- tblPerson tblPersonSoftware ...
10
2097
by: teddysnips | last post by:
Application is a Work Tracking/Timesheet database. The increments of work are stored in the TimesheetItem table. This contains, inter alia, the Work Code, the Start and the Duration that the...
8
9211
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
8
6274
by: Carl | last post by:
Hi, I hope someone can share some of their professional advice and help me out with my embarissing problem concerning an Access INSERT query. I have never attempted to create a table with...
3
1612
by: NuB | last post by:
I have an app that inserts records into a SQL db, I have a file that I'm reading to get the data out of, aka 'records', how can I determine of the record has been inserted into the database so i...
4
2185
by: Mike Hnatt | last post by:
My goal is to get data from an XML file into a couple of tables in an Access database. The XML file is a little complex so I need control over what I do (I can't just read it into a dataset). ...
0
4155
by: Peter Nofelt | last post by:
Hi all, ISSUE: ==================== In SQL 2005 (sp2) I get the following error when preforming a bulk insert with an associated xml format file: "Could not bulk insert. Unknown version of...
0
2135
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
8
6463
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
377
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.