Connecting Tech Pros Worldwide Forums | Help | Site Map

problem in loading a text file int mysql

Newbie
 
Join Date: Jun 2007
Posts: 3
#1: Jun 18 '07
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

Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Jun 18 '07

re: problem in loading a text file int mysql


Quote:

Originally Posted by vaibhavkansara

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?
Newbie
 
Join Date: Jun 2007
Posts: 3
#3: Jun 20 '07

re: problem in loading a text file int mysql


Quote:

Originally Posted by r035198x

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.
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,083
#4: Jun 22 '07

re: problem in loading a text file int mysql


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.
Reply