Forum Moderators: coopster
<?php
...
$upfile = '../uploads/'.$userfile_name;
$id = $HTTP_GET_VARS["id"];
$sql = 'LOAD DATA LOCAL INFILE \'$upfile\' INTO TABLE `fund_$id` FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\'( `first_n` , `last_n` , `class` , `product` )';
...
?>
The problem being that when I execute this script I get the error that tablename fund_$id doesn't exist...obviously it is not reading the variable $id properly. I'm led to believe that it's reading it literally (obviously) and not using the value of $id. How must this be formatted so that it does read it? thankyou.
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ''$ourtable' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY
I have now got it reading the variable with the following:
$sql = 'LOAD DATA LOCAL INFILE ' . $upfile . ' INTO TABLE ' . $ourtable .' FIELDS TERMINATED BY \',\' ENCLOSED BY \'"\' ESCAPED BY \'\\\\\' LINES TERMINATED BY \'\\r\\n\'( `first_n` , `last_n` , `class` , `product` )';
However I now get another error:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '../uploads/Book1.csv INTO TABLE fund_7 FIELDS TERMINATED BY ','
Not really sure what this error could be, since I got the code straight from PHPMyAdmin.