473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

problem in loading a text file int mysql

Hello friends,
I am vaibhav
I am a new to PHP/MYSQL.I have a problem to uploading a text file into MYSQL using php, and a text file is a tabdelimited file so pleas give me solution as soon as possible .Thanks in advance.

Vaibhav
Jun 18 '07 #1
3 1960
r035198x
13,262 8TB
Hello friends,
I am vaibhav
I am a new to PHP/MYSQL.I have a problem to uploading a text file into MYSQL using php, and a text file is a tabdelimited file so pleas give me solution as soon as possible .Thanks in advance.

Vaibhav
Can you give more details? Are you using LOAD DATA LOCAL INFILE?
Jun 18 '07 #2
Can you give more details? Are you using LOAD DATA LOCAL INFILE?

if($HTTP_POST_VARS['cmdup'])
{
$user="root";
$pass="";
$dbase="attendence";
$server="localhost";
$conn =mysql_connect("localhost","root","") or die("Connection attempt failed - ".mysql_error());
$db = mysql_select_db("attendence",$conn) or die(mysql_error());
echo $db;
$handle = fopen ("C:\\Program Files\\typo3\\attendence\\ats.txt","r");
echo $handle."<br>\n";
while ($data = fgetcsv($handle,1000,"\t"))
{

$sql="insert into ats (empno,emp_name,shift,arrvl,out1,in2,out2,in3,out3 ,late,early,wkrhr,exthr,prs,remarks)
values('$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]','$data[7]','$data[8]','$data[9]','$data[10]','$data[11]','$data[12]','$data[13]','$data[14]','$data[15]')";
$result = mysql_query($sql) or die("Invalid query: .<br>\n " .mysql_error());
echo $sql;

}

in this first line it give error Resource id #4
this is the code now when i click on the upload button it insert null value into the table.so what can i do. i also used LOAD DATA INFILE but it is not working.so plz give reply immediate.

my file is like
sr_no empno empname
1 1 aaaaaa
2 2 bbbbbb
and it is a text file.
Jun 20 '07 #3
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. error Resource id #4
Are you sure this is all it says?. This could be a file open error or database connection error. We have no idea because your code goes blindly ahead assuming everythig is working. Get some error trapping code in and switch on every level of error reporting.
Jun 22 '07 #4

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

Similar topics

1
by: Cindy Lee | last post by:
I need to insert rows into MySql database from oracle, which I imagine is a rather common task. The path I decided to take is write a java procedure, as recommended in the manual. However, java...
0
by: cmars | last post by:
Hi, I want to insert massive amounts of data in near real-time into a MySQL database. The data is in a structured binary format, and I have code that parses the data into logical data structures. ...
0
by: Mark Fisher | last post by:
I cannot seem to store binary data as a BLOB. I used the following to create a table capable of holding a BLOB: CREATE TABLE blob_table ( id INT UNSIGNED NOT NULL AUTO_INCREMENT,...
0
by: adrian GREEMAN | last post by:
When I try to import a text file with new data for an existing table I get the error "1148 - the used command is not allowed with this MySQL version." I have tried with both PHPMyAdmin2.3 and...
0
by: Z. S.Ghand | last post by:
--0-1230766640-1061225344=:24593 Content-Type: text/plain; charset=us-ascii Hi All; I have written a small mysql program with c++ in linux. i compile it by g++ -L/usr/lib/mysql...
2
by: Pindz | last post by:
Hello, I have a excel spreadsheet from which I would like to load data into a table in mysql. Can you please give me an example of the above. Thanks in advance Nagsy
4
by: spwpreston | last post by:
Hello, I am new to MySQL. I am trying to load from a text file to a table, and am having problems with the fields in the text file being translated to the correct fields in the TABLE. Right...
0
by: PowerLifter1450 | last post by:
Hi everyone, hoepfully someone can help me with this problem, as I am new to Linux and not so sure how to troubleshoot this problem. I installed MySQL 4.1.21 on Fedora Core two without receiving...
8
by: geert | last post by:
Hi all, I have a mac mini running maocosx 10.5 leopard I want to deploy a django project on. My backend is MySQL, and I have it running as a 64- bit app. Of course, apache2 is also running as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.