Note this var_dump

array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt"
["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14)
"/tmp/phpOxqCnD" ["error"]=> int(0) ["size"]=> int(61) } } array(1) {
["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt" ["type"]=>
string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpOxqCnD"
["error"]=> int(0) ["size"]=> int(61) } } string(165) " LOAD DATA LOCAL
INFILE '/tmp/phpOxqCnD' INTO TABLE `3` FIELDS TERMINATED BY ',' OPTIONALLY
ENCLOSED BY '\'' LINES TERMINATED BY "\r\n" IGNORE 1 LINES" $sqlDuplicate
column name 'Array'


array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt"
is where my problem is.
On my line 8   ->  $fileData = $_FILES["file"]; if I switch it to 'name'
(like I am thinking it should be) I get an undefined variable error. With it
as 'file', I get no error but no data either.


Code:
*****************************
<?php
var_dump($_FILES);
//db connection
require 'dbConnect.php';
//session file
require_once('../auth.php');
function uploadList(){
$fileData = $_FILES["file"];
//$fileData = ["name"];
//var_dump($_FILES["name"]);
var_dump($_FILES);
$memberID = $_SESSION["SESS_MEMBER_ID"];
if ($fileData["type"] == "text/plain")
{
if ($fileData["error"] > 0)
{
echo "Return Code: " . $fileData['error'] . "<br />";
}
else
{
dbConnect();
mysql_select_db('mailList') or die(mysql_error());
$tmp_name = $fileData["tmp_name"];
$presql = "CREATE TABLE IF NOT EXISTS `{$memberID}` (id MEDIUMINT
AUTO_INCREMENT PRIMARY KEY UNIQUE)";
$midsql = "ALTER TABLE `{$memberID}` ADD {$fileData} VARCHAR(60)";
$sql = <<<EOF
LOAD DATA LOCAL INFILE '{$tmp_name}'
INTO TABLE `{$memberID}`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\''
LINES TERMINATED BY "\\r\\n"
IGNORE 1 LINES
EOF;
var_dump($sql);
echo '$sql';
mysql_query($presql) or die(mysql_error());
mysql_query($midsql) or die(mysql_error());
mysql_query($sql) or die(mysql_error());
var_dump($sql);
echo '$sql';
if(mysql_error())
{
echo(mysql_error());
}
else
{
print('Import of campaign emails sucessfull into mysql table.');
}
}
}
else
{
print('Invalid file type. Please make sure it is a text file.');
}
}

//var_dump($_FILES);
uploadList();
?>

***********************************************

mysql> SHOW CREATE TABLE `3`;
+-------+-------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------------------+
| Table | Create Table |
+-------+-------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------------------+
| 3 | CREATE TABLE `3` (
`id` mediumint(9) NOT NULL AUTO_INCREMENT,
`Array` varchar(60) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 |
+-------+-------------------------------------------------------------------
----------------------------------------------------------------------------
------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM `3`;
+----+-------+
| id | Array |
+----+-------+
| 1 | NULL |
| 2 | NULL |
| 3 | NULL |
| 4 | NULL |
| 5 | NULL |
| 6 | NULL |
| 7 | NULL |
| 8 | NULL |
| 9 | NULL |
| 10 | NULL |
| 11 | NULL |
| 12 | NULL |
+----+-------+
12 rows in set (0.00 sec)

******************************

 

Brad

Reply via email to