Page 1 of 1

Simple ? - table not found

Posted: Sat May 29, 2004 7:50 pm
by SBro
I have the following code...

<?php
...

$upfile = 'uploads/'.$userfile_name;

$id = $HTTP_GET_VARS["id"];

echo "id - $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` )';

...
?>

Now the problem I have is when I run it I get the following error:
Table 'beper_fundraising.fund_$id' doesn't exist

I can't for the life of me figure out why it's not reading in the "$id" variable?? After all on the line above I echo'd it to make sure it was reading it, and yes it printed out the id as expected. I see the error as being something in the sql code, but can't figure it out, any help would be appreciated, thanks.

Posted: Sat May 29, 2004 8:33 pm
by feyd
you are using a literal string.. the variable $id will not be parsed out to whatever $id equals. (the $sql assignment, that is)

Posted: Sat May 29, 2004 9:10 pm
by SBro
So what would be the correct way of referencing it ?

Posted: Sat May 29, 2004 9:14 pm
by feyd
make your insertion 1 line.

Posted: Sun May 30, 2004 4:24 pm
by JAM
Or... (the ever on going discussion on ' vs. ", I know)

Code: Select all

$sql = 'LOAD DATA LOCAL INFILE ''$upfile'' INTO TABLE ''fund_' . $id . ''' FIELDS ...