problem in loading a text file int mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vaibhavkansara
    New Member
    • Jun 2007
    • 3

    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
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    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?

    Comment

    • vaibhavkansara
      New Member
      • Jun 2007
      • 3

      #3
      Originally posted by r035198x
      Can you give more details? Are you using LOAD DATA LOCAL INFILE?

      if($HTTP_POST_V ARS['cmdup'])
      {
      $user="root";
      $pass="";
      $dbase="attende nce";
      $server="localh ost";
      $conn =mysql_connect( "localhost","ro ot","") or die("Connection attempt failed - ".mysql_error() );
      $db = mysql_select_db ("attendence",$ conn) or die(mysql_error ());
      echo $db;
      $handle = fopen ("C:\\Progra m Files\\typo3\\a ttendence\\ats. txt","r");
      echo $handle."<br>\n ";
      while ($data = fgetcsv($handle ,1000,"\t"))
      {

      $sql="insert into ats (empno,emp_name ,shift,arrvl,ou t1,in2,out2,in3 ,out3,late,earl y,wkrhr,exthr,p rs,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($sq l) 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.

      Comment

      • code green
        Recognized Expert Top Contributor
        • Mar 2007
        • 1726

        #4
        Code:
        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.

        Comment

        Working...