Simple ? - table not found

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Simple ? - table not found

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
SBro
Forum Commoner
Posts: 98
Joined: Tue Sep 30, 2003 10:06 pm

Post by SBro »

So what would be the correct way of referencing it ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

make your insertion 1 line.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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 ...
Post Reply