CSV/TXT file imported via PHP into MySQL

From: Date: Mon, 10 Jun 2002 16:37:31 +0000
Subject: CSV/TXT file imported via PHP into MySQL
Groups: php.db 
Request: Send a blank email to php-db+get-19721@lists.php.net to get a copy of this message
I have a form on a PHP page with which I wish to load a tab delimited text file into a UNIX based MySQL database By using PHPMyAdmin I have tested whether I can upload the file, using MyAdmin to help me construct the Query and to date in MyAdmin it works fine. Taking the query and splitting it across two pages (one for receiving the file, and to action the query) seems to stop it from working. I have detailed the pertinent aspects below. My question is really to do with whether there is a file permissions setting or requirement that I have to be aware of, or if there is merely something else I can do. Form code: echo "<form method=\"post\" action=\"$PHP_SELF?command=create\" enctype=\"multipart/form-data\">"; echo "\n<table width=\"300\"><tr><td><input type=\"file\" name=\"textfile\"></td>"; echo "\n\n<td width=\"50\"><input type=\"submit\" name=\"submit\" value=\"Load File\"></td></tr></table></form>"; Query section: switch ($command) { case 'create': echo "<br>$textfile"; \\merely existing to run checks $query = "LOAD DATA LOCAL INFILE '" . $textfile . "' INTO TABLE pebble_email_addresses FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\r\n' (firstname, surname, email) "; echo "<br>$query"; \\merely existing to run checks $sql_query_result = @mysql_query($query, $sql_userdb); if ($sql_query_result and @mysql_affected_rows() > 0) { //Worked OK echo "<br>it worked"; } else { echo "<br>it didn't"; break; I have yet to get the damn query to import anything at all! HELP Thanks in Advance! Keiran

« previous php.db (#19721) next »