RE: Re: Stuck trying to upload and grab file name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Same thing

<?php
var_dump($_FILES);
//db connection
require 'dbConnect.php';
//session file
require_once('../auth.php');
function uploadList(){
        $fileData = $_FILES["file"];
        var_dump($_FILES["file"]);
        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);
                        mysql_query($midsql);
                        mysql_query($sql);
                        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();
?>

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

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)

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









array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt"
["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14)
"/tmp/phpKeJFI0" ["error"]=> int(0) ["size"]=> int(61) } } array(5) {
["name"]=> string(14) "emailsTest.txt" ["type"]=> string(10) "text/plain"
["tmp_name"]=> string(14) "/tmp/phpKeJFI0" ["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/phpKeJFI0" ["error"]=> int(0) ["size"]=> int(61) } }
string(165) "	 LOAD DATA LOCAL INFILE '/tmp/phpKeJFI0' INTO TABLE `3`
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY
"\r\n" IGNORE 1 LINES" $sqlstring(165) "	 LOAD DATA LOCAL INFILE
'/tmp/phpKeJFI0' INTO TABLE `3` FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED
BY '\'' LINES TERMINATED BY "\r\n" IGNORE 1 LINES" $sqlImport of campaign
emails sucessfull into mysql table.



-----Original Message-----
From: Karl DeSaulniers [mailto:karl@xxxxxxxxxxxxxxx] 
Sent: Wednesday, July 25, 2012 10:46 PM
To: php-db@xxxxxxxxxxxxx
Subject: Re:  Re: Stuck trying to upload and grab file name

Brad,
Try this and let me know if it worked. I'm curious.

$fileData = $_FILES['file'];

...

dbConnect();
mysql_select_db('mailList') or die(mysql_error()); $presql = "CREATE TABLE
IF NOT EXISTS `".mysql_real_escape_string($memberID)."` (id MEDIUMINT
AUTO_INCREMENT PRIMARY KEY UNIQUE)"; $midsql = "ALTER TABLE
`".mysql_real_escape_string($memberID)."` ADD
'".mysql_real_escape_string($fileData)."' VARCHAR(60)"; $sql = "LOAD DATA
LOCAL INFILE '".mysql_real_escape_string($_FILES['tmp_name'])."' INTO TABLE
`".mysql_real_escape_string($memberID)."` FIELDS TERMINATED BY '\,'  
OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY "\r\n" IGNORE 1 LINES";

...

Best,
Karl

> $file
On Jul 25, 2012, at 8:57 PM, Brad wrote:

> That's a little presumptuous don't you think?
> I runs without error now but my test data is not in the database?
>
> array(1) { ["file"]=> array(5) { ["name"]=> string(14) 
> "emailsTest.txt"
> ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) 
> "/tmp/phpkVycB6" ["error"]=> int(0) ["size"]=> int(61) } } Import of 
> campaign emails sucessfull into mysql table.
>
> <?php
> var_dump($_FILES);
> //db connection
> require 'dbConnect.php';
> //session file
> require_once('../auth.php');
> function uploadList(){
>        $file = $_FILES["file"];
>        //var_dump($_FILES["file"]);
>        $memberID = $_SESSION["SESS_MEMBER_ID"];
>        if ($file["type"] == "text/plain")
>                {
>                if ($file["error"] > 0)
>                        {
>                        echo "Return Code: " . $file['error'] . "<br /
> >";
>                }
>                else
>                        {
>                        dbConnect();
>                        mysql_select_db('mailList') or 
> die(mysql_error());
>                        $tmp_name =  $file["tmp_name"];
>                        $presql = "CREATE TABLE IF NOT EXISTS 
> `{$memberID}` (id MEDIUMINT AUTO_INCREMENT PRIMARY KEY UNIQUE)";
>                        $midsql = "ALTER TABLE `{$memberID}` ADD 
> {$file} 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);
>                        mysql_query($midsql);
>                        mysql_query($sql);
>                        //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();
> ?>
>
>
>
>
> Brad Sumrall
> NYCTelecomm.com
> 212 444-2996
>
>
> -----Original Message-----
> From: lists-php [mailto:replies-lists-d5y3-php@xxxxxxxxxxxxxxxxxxxxx]
> Sent: Wednesday, July 25, 2012 9:35 PM
> To: Brad
> Subject: RE:  Re: Stuck trying to upload and grab file name
>
> Is this supposed to be what you submitted to mysql? I suspect not, as 
> among things, it includes the returned mysql error.
>
> Sorry, but I don't think you get the basics of debugging code.
>
> I would suggest that you find someone who is willing to give you 
> sample code and help you **off list** (this level of tutorial really 
> doesn't belong on a mailing list).
>
> Good luck.
>
>
>
> ------------ Original Message ------------
>> Date: Wednesday, July 25, 2012 09:24:53 PM -0400
>> From: Brad <nyctelecomm@xxxxxxxxx>
>> To: 'lists-php' <replies-lists-d5y3-php@xxxxxxxxxxxxxxxxxxxxx>
>> Subject: RE:  Re: Stuck trying to upload and grab file name
>>
>> https://gist.github.com/3179723
>>
>> array(1) { ["file"]=> array(5) { ["name"]=> string(14) 
>> "emailsTest.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=>
>> string(14) "/tmp/phpepEKoj" ["error"]=> int(0) ["size"]=> int(61) } }
>> string(188) " LOAD DATA LOCAL INFILE '/tmp/phpepEKoj' ALTER TABLE `3` 
>> ADD Array VARCHAR(60); FIELDS TERMINATED BY ','
>> OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY "\r\n" IGNORE 1 
>> LINES"
>> $sqlYou have an error in your SQL syntax; check the manual that 
>> corresponds to your MySQL server version for the right syntax to use 
>> near 'ALTER TABLE `3` ADD Array VARCHAR(60); FIELDS TERMINATED BY ','
>> OPTIONALLY EN' at line 2
>>
>> -----Original Message-----
>> From: lists-php
>> [mailto:replies-lists-d5y3-php@xxxxxxxxxxxxxxxxxxxxx]  Sent:
>> Wednesday, July 25, 2012 8:57 PM
>> To: Brad
>> Subject: RE:  Re: Stuck trying to upload and grab file name
>>
>> No. What you have there is the dump *after* you've passed things to 
>> mysql -- including the mysql error. Look at what you are passing to 
>> mysql *before* you actually feed it to mysql.
>>
>> I suspect you are missing a mysql command terminator (semicolon) or 
>> two so you are running commands together. E.g., after the "load data"
>> command -- but it's mostly impossible to tell without cleaner detail.
>>
>> Just as a general coding practice issue -- why are you trying to 
>> string that group of commands into one set that you dump to mysql in 
>> a single set. It would be much cleaner, and more controllable, to do 
>> the different mysql commands as separate statements.
>>
>>
>> ------------ Original Message ------------
>>> Date: Wednesday, July 25, 2012 08:43:51 PM -0400
>>> From: Brad <nyctelecomm@xxxxxxxxx>
>>> To: 'lists-php'
>>> Subject: RE:  Re: Stuck trying to upload and grab file name
>>>
>>> I believe I was already doing that on line 33?
>>> https://gist.github.com/3179584
>>>
>>>
>>> array(1) { ["file"]=> array(5) { ["name"]=> string(14) 
>>> "emailsTest.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=>
>>> string(14) "/tmp/phpKsDHhS" ["error"]=> int(0) ["size"]=>
>>> int(61) } }
>>> string(188) " LOAD DATA LOCAL INFILE '/tmp/phpKsDHhS' ALTER TABLE 
>>> `3` ADD Array VARCHAR(60); FIELDS TERMINATED BY ','
>>> OPTIONALLY ENCLOSED BY '\'' LINES TERMINATED BY "\r\n" IGNORE 1 
>>> LINES"  $sqlYou have an error in your SQL syntax; check the manual 
>>> that  corresponds to your MySQL server version for the right syntax 
>>> to use  near 'ALTER TABLE `3` ADD Array VARCHAR(60); FIELDS 
>>> TERMINATED BY ','  OPTIONALLY EN' at line 2
>>>
>>> Brad
>>>
>>>
>>>
>>> -----Original Message-----
>>> From: lists-php
>>> [mailto:replies-lists-d5y3-php@xxxxxxxxxxxxxxxxxxxxx]  Sent:
>>> Wednesday, July 25, 2012 8:31 PM
>>> To: Brad
>>> Subject: RE:  Re: Stuck trying to upload and grab file name
>>>
>>>>
>>>>
>>>> ------------ Original Message ------------
>>>>> Date: Wednesday, July 25, 2012 07:33:09 PM -0400
>>>>> From: Brad <nyctelecomm@xxxxxxxxx>
>>>>> Subject: RE:  Re: Stuck trying to upload and grab file 
>>>>> name
>>>>>
>>>>> Switching it to -> ALTER TABLE `{$memberID}` ADD {$tmp_name} 
>>>>> VARCHAR(60); produces the same error.
>>>>> For the record $tmp_name is just gibberish and should not be the 
>>>>> final  column name.
>>>>>
>>>>> Brad
>>>>>
>>>>
>>>> Echo the statement out (after the variable substitutions have
>>>> taken   place), and then work with that at the mysql command
>>>> line. You'll likely figure out the issue much faster (it might even 
>>>> be  obvious from what gets displayed).
>>>>
>>>>   - Richard
>>>>
>>>>
>>>> Date: Wednesday, July 25, 2012 08:16:07 PM -0400
>>>> From: Brad <nyctelecomm@xxxxxxxxx>
>>>>
>>>> Unfortunately that has already been done and that exact method is 
>>>> what  got me this far. I can visually confirm that I am calling on 
>>>> the  correct names/variables.
>>>>
>>>> array(1) { ["file"]=> array(5) { ["name"]=> string(14) 
>>>> "emailsTest.txt" ["type"]=> string(10) "text/plain"
>>>> ["tmp_name"]=> string(14) "/tmp/phpec4hX9" ["error"]=> int(0)
>>>> ["size"]=> int(61) } }   array(5) { ["name"]=> string(14)
>>>> "emailsTest.txt" ["type"]=> string(10) "text/plain"
>>>> ["tmp_name"]=> string(14) "/tmp/phpec4hX9" ["error"]=> int(0)
>>>> ["size"]=> int(61) } $sqlYou have an error in your   SQL syntax;
>>>> check the manual that corresponds to your MySQL server   version
>>>> for the right syntax to use near 'ALTER TABLE `3` ADD Array 
>>>> VARCHAR(60); FIELDS TERMINATED BY ',' OPTIONALLY EN'
>>>> at line 2
>>>>
>>>> Brad
>>>>
>>>
>>> What you're showing isn't what I mean.
>>>
>>> What I'm suggesting is the actual mysql statement (in this case your 
>>> ALTER line) so you can see *exactly* what you're passing to mysql.
>>> The  mysql statement that you echo from your php code should be able 
>>> to  copied/pasted directly to the mysql command prompt. The above 
>>> dump  isn't that.
>>>
>>>
>>>
>>>    - Richard
>>>
>>>
>>
>> ------------ End Original Message ------------
>>
>
> ------------ End Original Message ------------
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: 
> http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux