RE: [PHP-DB] Re: Stuck trying to upload and grab file name
Same thing 0) { echo "Return Code: " . $fileData['error'] . ""; } 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 = << *** 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:k...@designdrumm.com] Sent: Wednesday, July 25, 2012 10:46 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] 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"
Re: [PHP-DB] 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. 0) { echo "Return Code: " . $file['error'] . ">"; } 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 = << 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-...@listmail.innovate.net] Sent: Wednesday, July 25, 2012 9:35 PM To: Brad Subject: RE: [PHP-DB] 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 To: 'lists-php' Subject: RE: [PHP-DB] 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-...@listmail.innovate.net] Sent: Wednesday, July 25, 2012 8:57 PM To: Brad Subject: RE: [PHP-DB] 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: We
RE: [PHP-DB] Re: Stuck trying to upload and grab file name
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. 0) { echo "Return Code: " . $file['error'] . ""; } 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 = << Brad Sumrall NYCTelecomm.com 212 444-2996 -----Original Message- From: lists-php [mailto:replies-lists-d5y3-...@listmail.innovate.net] Sent: Wednesday, July 25, 2012 9:35 PM To: Brad Subject: RE: [PHP-DB] 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 > To: 'lists-php' > Subject: RE: [PHP-DB] 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-...@listmail.innovate.net] Sent: > Wednesday, July 25, 2012 8:57 PM > To: Brad > Subject: RE: [PHP-DB] 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 >> To: 'lists-php' >> Subject: RE: [PHP-DB] 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 v
RE: [PHP-DB] Re: Stuck trying to upload and grab file name
Updated code with var_dump; https://gist.github.com/3179506 Brad -Original Message- From: lists-php [mailto:replies-lists-d5y3-...@listmail.innovate.net] Sent: Wednesday, July 25, 2012 7:55 PM To: Brad Subject: RE: [PHP-DB] Re: Stuck trying to upload and grab file name Original Message > Date: Wednesday, July 25, 2012 07:33:09 PM -0400 > From: Brad > To: 'Karl DeSaulniers' > Cc: php-db@lists.php.net > Subject: RE: [PHP-DB] 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Re: Stuck trying to upload and grab file name
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 -Original Message- From: lists-php [mailto:replies-lists-d5y3-...@listmail.innovate.net] Sent: Wednesday, July 25, 2012 7:55 PM To: Brad Subject: RE: [PHP-DB] Re: Stuck trying to upload and grab file name ---- Original Message > Date: Wednesday, July 25, 2012 07:33:09 PM -0400 > From: Brad > To: 'Karl DeSaulniers' > Cc: php-db@lists.php.net > Subject: RE: [PHP-DB] 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] 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 -Original Message- From: Karl DeSaulniers [mailto:k...@designdrumm.com] Sent: Wednesday, July 25, 2012 7:18 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] Re: Stuck trying to upload and grab file name On Jul 25, 2012, at 6:11 PM, Brad wrote: > I am only uploading the temporary file. The filename is acquired via > -> $file = $_FILES["file"]; and that is what is included in the naming > of the column. > > > > -Original Message- > From: Karl DeSaulniers [mailto:k...@designdrumm.com] > Sent: Wednesday, July 25, 2012 7:05 PM > To: php-db@lists.php.net > Subject: Re: [PHP-DB] Re: Stuck trying to upload and grab file name > > On Jul 25, 2012, at 5:49 PM, Brad wrote: > >> I revamped my logic, proved the SQL works in a client the way I want >> and once again, I am hitting the same mysql brick wall. >> >> >> >> > >> var_dump($_FILES); >> >> //db connection >> >> require 'dbConnect.php'; >> >> //session file >> >> require_once('../auth.php'); >> >> function uploadList(){ >> >> $file = $_FILES["file"]; >> >> $memberID = $_SESSION["SESS_MEMBER_ID"]; >> >> if ($file["type"] == "text/plain") >> >> { >> >> if ($file["error"] > 0) >> >> { >> >> echo "Return Code: " . $file['error'] . ">> "; >> >> } >> >> 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)"; >> >> $sql = <<> >> LOAD DATA LOCAL INFILE '{$tmp_name}' >> >> ALTER TABLE `{$memberID}` ADD {$file} >> VARCHAR(60); >> >> FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY >> '\\'' >> >> LINES TERMINATED BY "\\r\\n" >> >> IGNORE 1 LINES >> >> EOF; >> >> mysql_query($presql); >> >> 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(); >> >> ?> >> >> >> >> error* >> >> >> >> array(1) { ["file"]=> array(5) { ["name"]=> string(14) >> "emailsTest.txt" >> ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) >> "/tmp/phpBKCv3n" ["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 >> >> >> >> proof it's supposed to work >> >> >> >> >> >> mysql> CREATE TABLE IF NOT EXISTS `215` (id MEDI
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
On Jul 25, 2012, at 6:11 PM, Brad wrote: I am only uploading the temporary file. The filename is acquired via -> $file = $_FILES["file"]; and that is what is included in the naming of the column. -Original Message- From: Karl DeSaulniers [mailto:k...@designdrumm.com] Sent: Wednesday, July 25, 2012 7:05 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] Re: Stuck trying to upload and grab file name On Jul 25, 2012, at 5:49 PM, Brad wrote: I revamped my logic, proved the SQL works in a client the way I want and once again, I am hitting the same mysql brick wall. 0) { echo "Return Code: " . $file['error'] . " "; } 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)"; $sql = << error* array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpBKCv3n" ["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 proof it's supposed to work mysql> CREATE TABLE IF NOT EXISTS `215` (id MEDIUMINT AUTO_INCREMENT PRIMARY KEY UNIQUE); Query OK, 0 rows affected (0.00 sec) mysql> ALTER TABLE `215` ADD emailList VARCHAR(40); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 Just currious and for my own edification. Why are you trying to store the temp name in your database? You should move and rename the file and then store that name in your database. If I understand temp_name, that name dissapears after done processing. Am I correct everyone? Shouldn't he move the file first and rename then store? and do you store the path in the database or just the name? Because the temp_name var has directory slashes in it and if those are not escaped it wont work. Best, 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 Try using that to store in the database and dont use it for the column name. use `mail_file` or something like that for the column name. 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-DB] Re: Stuck trying to upload and grab file name
I am only uploading the temporary file. The filename is acquired via -> $file = $_FILES["file"]; and that is what is included in the naming of the column. -Original Message- From: Karl DeSaulniers [mailto:k...@designdrumm.com] Sent: Wednesday, July 25, 2012 7:05 PM To: php-db@lists.php.net Subject: Re: [PHP-DB] Re: Stuck trying to upload and grab file name On Jul 25, 2012, at 5:49 PM, Brad wrote: > I revamped my logic, proved the SQL works in a client the way I want > and once again, I am hitting the same mysql brick wall. > > > > > var_dump($_FILES); > > //db connection > > require 'dbConnect.php'; > > //session file > > require_once('../auth.php'); > > function uploadList(){ > >$file = $_FILES["file"]; > >$memberID = $_SESSION["SESS_MEMBER_ID"]; > >if ($file["type"] == "text/plain") > >{ > >if ($file["error"] > 0) > >{ > >echo "Return Code: " . $file['error'] . " >"; > >} > >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)"; > >$sql = << >LOAD DATA LOCAL INFILE '{$tmp_name}' > >ALTER TABLE `{$memberID}` ADD {$file} > VARCHAR(60); > >FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY > '\\'' > >LINES TERMINATED BY "\\r\\n" > >IGNORE 1 LINES > > EOF; > >mysql_query($presql); > >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(); > > ?> > > > > error* > > > > array(1) { ["file"]=> array(5) { ["name"]=> string(14) > "emailsTest.txt" > ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) > "/tmp/phpBKCv3n" ["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 > > > > proof it's supposed to work > > > > > > mysql> CREATE TABLE IF NOT EXISTS `215` (id MEDIUMINT AUTO_INCREMENT > PRIMARY > KEY UNIQUE); > > Query OK, 0 rows affected (0.00 sec) > > > > mysql> ALTER TABLE `215` ADD emailList VARCHAR(40); > > Query OK, 0 rows affected (0.00 sec) > > Records: 0 Duplicates: 0 Warnings: 0 > > > Just currious and for my own edification. Why are you trying to store the temp name in your database? You should move and rename the file and then store that name in your database. If I understand temp_name, that name dissapears after done processing. Am I correct everyone? Shouldn't he move the file first and rename then store? and do you store the path in the database or just the name? Because the temp_name var has directory slashes in it and if those are not escaped it wont work. Best, 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
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
On Jul 25, 2012, at 5:49 PM, Brad wrote: I revamped my logic, proved the SQL works in a client the way I want and once again, I am hitting the same mysql brick wall. 0) { echo "Return Code: " . $file['error'] . ">"; } 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)"; $sql = << ALTER TABLE `{$memberID}` ADD {$file} VARCHAR(60); FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\'' LINES TERMINATED BY "\\r\\n" IGNORE 1 LINES EOF; mysql_query($presql); 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(); ?> error* array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpBKCv3n" ["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 proof it's supposed to work mysql> CREATE TABLE IF NOT EXISTS `215` (id MEDIUMINT AUTO_INCREMENT PRIMARY KEY UNIQUE); Query OK, 0 rows affected (0.00 sec) mysql> ALTER TABLE `215` ADD emailList VARCHAR(40); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0 Just currious and for my own edification. Why are you trying to store the temp name in your database? You should move and rename the file and then store that name in your database. If I understand temp_name, that name dissapears after done processing. Am I correct everyone? Shouldn't he move the file first and rename then store? and do you store the path in the database or just the name? Because the temp_name var has directory slashes in it and if those are not escaped it wont work. Best, 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-DB] Re: Stuck trying to upload and grab file name
I revamped my logic, proved the SQL works in a client the way I want and once again, I am hitting the same mysql brick wall. 0) { echo "Return Code: " . $file['error'] . ""; } 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)"; $sql = << error* array(1) { ["file"]=> array(5) { ["name"]=> string(14) "emailsTest.txt" ["type"]=> string(10) "text/plain" ["tmp_name"]=> string(14) "/tmp/phpBKCv3n" ["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 proof it's supposed to work mysql> CREATE TABLE IF NOT EXISTS `215` (id MEDIUMINT AUTO_INCREMENT PRIMARY KEY UNIQUE); Query OK, 0 rows affected (0.00 sec) mysql> ALTER TABLE `215` ADD emailList VARCHAR(40); Query OK, 0 rows affected (0.00 sec) Records: 0 Duplicates: 0 Warnings: 0
[PHP-DB] RE: Stuck trying to upload and grab file name
I wanted to start off by saying thank you to the list for your warm support. I was working with jonez from irc.oftc.net #php and we were able to far enough into the issue for me to realize I'm an idiot. I am creating a new table like I wanted but should be creating new field due to a little paradox I create myself with the need for at least one field in the creation process. I should be creating a new field anyways. Here is the updated code but it will be changing a lot in a few moments. 0) { echo "Return Code: " . $file['error'] . ""; } else { dbConnect(); mysql_select_db('mailList') or die(mysql_error()); $tmp_name = $file["tmp_name"]; //$presql = "CREATE TABLE IF NOT EXISTS {$memberID}_{$file}"; $presql = "CREATE TABLE IF NOT EXISTS dumb_table"; $sql = <<
[PHP-DB] RE: Stuck trying to upload and grab file name
Wtf, whts happening here??? Getting freakin hundreds of emails, if you got stuckup, you need to resolve it by urself, dont email for silly doubts.. Sent from my smart phone -Original message- From: Graham H. Sent: 24/07/2012, 10:16 pm To: jim.gi...@albanyhandball.com Cc: php-db@lists.php.net Subject: Re: [PHP-DB] Re: Stuck trying to upload and grab file name Okay. That line is also in the Pastie code :) Though it isn't in the OP. Hence my (and your) confusion now. Line 20 from here: http://pastie.org/4317155 also line 24. On Tue, Jul 24, 2012 at 10:44 AM, Jim Giner wrote: > On 7/24/2012 12:40 PM, Graham H. wrote: > >> If by "the line" you mean: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" >> >> That is from the bottom of this Pastie link: http://pastie.org/4317155 >> >> >>> $file = $_FILES["file"]["tmp_name"]; >>> >>> >>> I meant the above line. > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Graham Holtslander Computer Systems Technologist www.graham.holtslander.com mene...@gmail.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
Okay. That line is also in the Pastie code :) Though it isn't in the OP. Hence my (and your) confusion now. Line 20 from here: http://pastie.org/4317155 also line 24. On Tue, Jul 24, 2012 at 10:44 AM, Jim Giner wrote: > On 7/24/2012 12:40 PM, Graham H. wrote: > >> If by "the line" you mean: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" >> >> That is from the bottom of this Pastie link: http://pastie.org/4317155 >> >> >>> $file = $_FILES["file"]["tmp_name"]; >>> >>> >>> I meant the above line. > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Graham Holtslander Computer Systems Technologist www.graham.holtslander.com mene...@gmail.com
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
On 7/24/2012 12:40 PM, Graham H. wrote: If by "the line" you mean: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" That is from the bottom of this Pastie link: http://pastie.org/4317155 $file = $_FILES["file"]["tmp_name"]; I meant the above line. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Stuck trying to upload and grab file name
On 7/24/2012 4:16 AM, Brad wrote: $file = $_FILES['file']['name']; //$presql = "CREATE TABLE IF NOT EXISTS (`$_SESSION[SESS_MEMBER_ID]_$file`)"; $presql = "CREATE TABLE IF NOT EXISTS `$_SESSION[SESS_MEMBER_ID]_$file`"; $sql = << Brad, Since you have defined a var $file containing what you need, why don't you use that var in your LOAD DATA line, instead of the convoluted $_FILES reference? If I may ask, what does the reference to $_SESSION[SESS_MEMBER_ID] accomplish? Haven' had an occasion to do this. I'm also wondering if the error you are receiving has anything to do with the name. It may be the syntax using those slashes as delimiter chars. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
If by "the line" you mean: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" That is from the bottom of this Pastie link: http://pastie.org/4317155 On Tue, Jul 24, 2012 at 10:29 AM, Jim Giner wrote: > > On 7/24/2012 12:05 PM, Graham H. wrote: > >> Does the problem have anything to do with this: >> >> >> ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" >> >> So this: >> >> $file = $_FILES["file"]["tmp_name"]; >> >> Would make $file == "/tmp/phpcLtE6W" >> >> I'm not sure if that's what you want. Seems more likely that you'd want it >> to be: >> >> $file = $_FILES["file"]["name"]; >> >> Useful? >> >> >> Graham, > The line you reference - I don't see that in my code (which is production > code) nor in the OP's code. > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Graham Holtslander Computer Systems Technologist www.graham.holtslander.com mene...@gmail.com
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
On 7/24/2012 12:05 PM, Graham H. wrote: Does the problem have anything to do with this: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" So this: $file = $_FILES["file"]["tmp_name"]; Would make $file == "/tmp/phpcLtE6W" I'm not sure if that's what you want. Seems more likely that you'd want it to be: $file = $_FILES["file"]["name"]; Useful? Graham, The line you reference - I don't see that in my code (which is production code) nor in the OP's code. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Stuck trying to upload and grab file name
Does the problem have anything to do with this: ["tmp_name"]=> string(14) "/tmp/phpcLtE6W" So this: $file = $_FILES["file"]["tmp_name"]; Would make $file == "/tmp/phpcLtE6W" I'm not sure if that's what you want. Seems more likely that you'd want it to be: $file = $_FILES["file"]["name"]; Useful? On Tue, Jul 24, 2012 at 9:18 AM, Brad wrote: > Thank you very much my friend. > The significant difference between your code and mine is that my file > contents are going into a MySQL database and it is this db function that is > crapping out. The SQL (with variables replaced with static values) runs > clean -> http://pastie.org/4302489 > But as soon as you throw in a variable/dynamic value, it just becomes a > mess. > > Brad > > > -Original Message- > From: Jim Giner [mailto:jim.gi...@albanyhandball.com] > Sent: Tuesday, July 24, 2012 8:45 AM > To: php-db@lists.php.net > Subject: [PHP-DB] Re: Stuck trying to upload and grab file name > > At the risk of being unable to understand all the posts that are here > already, here is some std. code that I use when I'm uploading a file. > > First - i capture the input field in a local var and all of its components > in other local vars to make my coding easier later on. > > $inputfield = $_POST['infile'];// infile is the html name of the > type='file' field > $destfolder = (where I want the end result stored) $outfile = (the filename > of the end result) $result = > HandleUploadedFile($inputfield,$destfolder,$outfile); > (handle $result after return) > *** > > The function I use: > > function HandleUploadedFile($inputfield,$destfolder,$outfile) > {// parm 1 is the name of the type=file field in the html; 2 & 3 are > path and output filename you want to store it in > global $msg,$ftype,$ferror,$fname,$fsize,$ftmpname; > $ftype = $_FILES[$inputfield]["type"]; > $ferror = $_FILES[$inputfield]["error"]; > $fname = $_FILES[$inputfield]["name"]; > $fsize = $_FILES[$inputfield]["size"]; > $ftmpname = $_FILES[$inputfield]["tmp_name"]; > // code up acceptabe filetypes here > if ( $ftype == "text/plain") > { > if ($ferror > 0) > { > $msg .= ' Upload error - return code was '.$ferror; > return False; > } > else > { > if (file_exists($destfolder . $fname)) > { > $msg .= " Duplicate filename - upload not done, > continuing."; > return True; > } > else > { > $msg .= " File has been uploaded to: " . $destfolder > .$outfile; > move_uploaded_file($ftmpname,$destfolder . $outfile); > return True; > } > } > } > else > { > $msg .= " Invalid file type for menu input upload"; > $msg .= " Type is ".$ftype; > return False; > } > } > > > You of course want to name your end result like the original filename, so > you will have to make a change to that parameter, but this will work for > you. > > -- > 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 > > -- Graham Holtslander Computer Systems Technologist www.graham.holtslander.com mene...@gmail.com
RE: [PHP-DB] Re: Stuck trying to upload and grab file name
Thank you very much my friend. The significant difference between your code and mine is that my file contents are going into a MySQL database and it is this db function that is crapping out. The SQL (with variables replaced with static values) runs clean -> http://pastie.org/4302489 But as soon as you throw in a variable/dynamic value, it just becomes a mess. Brad -Original Message- From: Jim Giner [mailto:jim.gi...@albanyhandball.com] Sent: Tuesday, July 24, 2012 8:45 AM To: php-db@lists.php.net Subject: [PHP-DB] Re: Stuck trying to upload and grab file name At the risk of being unable to understand all the posts that are here already, here is some std. code that I use when I'm uploading a file. First - i capture the input field in a local var and all of its components in other local vars to make my coding easier later on. $inputfield = $_POST['infile'];// infile is the html name of the type='file' field $destfolder = (where I want the end result stored) $outfile = (the filename of the end result) $result = HandleUploadedFile($inputfield,$destfolder,$outfile); (handle $result after return) *** The function I use: function HandleUploadedFile($inputfield,$destfolder,$outfile) {// parm 1 is the name of the type=file field in the html; 2 & 3 are path and output filename you want to store it in global $msg,$ftype,$ferror,$fname,$fsize,$ftmpname; $ftype = $_FILES[$inputfield]["type"]; $ferror = $_FILES[$inputfield]["error"]; $fname = $_FILES[$inputfield]["name"]; $fsize = $_FILES[$inputfield]["size"]; $ftmpname = $_FILES[$inputfield]["tmp_name"]; // code up acceptabe filetypes here if ( $ftype == "text/plain") { if ($ferror > 0) { $msg .= ' Upload error - return code was '.$ferror; return False; } else { if (file_exists($destfolder . $fname)) { $msg .= " Duplicate filename - upload not done, continuing."; return True; } else { $msg .= " File has been uploaded to: " . $destfolder .$outfile; move_uploaded_file($ftmpname,$destfolder . $outfile); return True; } } } else { $msg .= " Invalid file type for menu input upload"; $msg .= " Type is ".$ftype; return False; } } You of course want to name your end result like the original filename, so you will have to make a change to that parameter, but this will work for you. -- 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
[PHP-DB] Re: Stuck trying to upload and grab file name
At the risk of being unable to understand all the posts that are here already, here is some std. code that I use when I'm uploading a file. First - i capture the input field in a local var and all of its components in other local vars to make my coding easier later on. $inputfield = $_POST['infile'];// infile is the html name of the type='file' field $destfolder = (where I want the end result stored) $outfile = (the filename of the end result) $result = HandleUploadedFile($inputfield,$destfolder,$outfile); (handle $result after return) *** The function I use: function HandleUploadedFile($inputfield,$destfolder,$outfile) {// parm 1 is the name of the type=file field in the html; 2 & 3 are path and output filename you want to store it in global $msg,$ftype,$ferror,$fname,$fsize,$ftmpname; $ftype = $_FILES[$inputfield]["type"]; $ferror = $_FILES[$inputfield]["error"]; $fname = $_FILES[$inputfield]["name"]; $fsize = $_FILES[$inputfield]["size"]; $ftmpname = $_FILES[$inputfield]["tmp_name"]; // code up acceptabe filetypes here if ( $ftype == "text/plain") { if ($ferror > 0) { $msg .= ' Upload error - return code was '.$ferror; return False; } else { if (file_exists($destfolder . $fname)) { $msg .= " Duplicate filename - upload not done, continuing."; return True; } else { $msg .= " File has been uploaded to: " . $destfolder .$outfile; move_uploaded_file($ftmpname,$destfolder . $outfile); return True; } } } else { $msg .= " Invalid file type for menu input upload"; $msg .= " Type is ".$ftype; return False; } } You of course want to name your end result like the original filename, so you will have to make a change to that parameter, but this will work for you. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php