load file to mysql table

A

Anonymous

Guest
ello all!
need help regarding the subject.
the code for the form

Code:
<form method="post" enctype="multipart/form-data" action="tryupload1.php">
      <br>
      <input type="file" name="filetoupload"><br>
      <input type="hidden" name="MAX_FILE_SIZE" value="51200>">
      <br>
      <input type="Submit" name="uploadform" value="Upload File">
      </form>

code in tryupload1.php

Code:
<?php
include ("connection.inc");
$filename =  $_FILES['filetoupload']['name'];
echo $filename;
$query="LOAD DATA INFILE '$filename' INTO TABLE 'table2'
	FIELDS TERMINATED BY ','  LINES TERMINATED BY '\\r\\n'";
echo $query;
$result=mysql_query($query)
              		or die ("Couldnt execute query");

?>

just a simple one.

after i try running the prog,no file is uploaded to the table(check from phpmyadmin).is there anything that i missed?i'd like to do the same like 'Insert data from a textfile into table' (as in phpmyadmin) to my website.

help plss.thanx in advance!
 
Try this

Code:
$query="LOAD DATA INFILE '$filename' INTO TABLE 'table2'   FIELDS TERMINATED BY ','  LINES TERMINATED BY '\r\n'";
or
Code:
$query="LOAD DATA INFILE '$filename' INTO TABLE 'table2'   FIELDS TERMINATED BY ','  LINES TERMINATED BY '\n'";


Let me know that the file u upload is .csv or not.
 
thanx 4 d response.
however to no avail.
i would like to upload a text file.
i try upload text and csv, however "couldnt execute query".
 
To execute above query your data should be in correct format and datatypes related.
 
please check the user permissions, the user must have FILE permissions to use LOAD DATA IN FILE
 
ello again!
ive no idea...
still not gettin any
can somebody suggest any tutorials that offer step by step procedures n clear instruction?
gone thru 'MySQL Reference Manual', and search other forum...
but..i just dun get it...
 
Code:
$filename =  $_FILES['filetoupload']['name'];

should be

Code:
$filename =  $_FILES['filetoupload']['tmp_name'];
 
pardon?
which part to use double slashes?
should i create an temporary folder somewhere?
 
Code:
<?php
include ("connection.inc");
$uploadfile = '/some/path/to/destination/file';

if (move_uploaded_file($_FILES['filetoupload']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}
echo $filename;
$query="LOAD DATA INFILE '$uploadfile' INTO TABLE table2
   FIELDS TERMINATED BY ','  LINES TERMINATED BY '\r\n' ";
$result=mysql_query($query)
                    or die ("Couldnt execute query");

?>
 
yeay :) ...at last...
the query is successfully executed...after i modified the query to LOAD DATA LOCAL INFILE..
i almost give up
thanx a lot
mwahxxx!
luv ya...
 
Back
Top