Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

NME

Using variables for Table names SQL

Recommended Posts

My code looks like this :

[code]$sql3 = mysql_query("INSERT INTO $list1 (user_id, fullname) VALUES ('$userid', '$name')") or die (mysql_error());[/code]

However, it does not work and I get the following 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 '(user_id, fullname) VALUES ('1121', 'Jeff Gordon')'

can anyone tell me what I'm doing wrong. Any help would be greatly appreciated. Thanks

Share this post


Link to post
Share on other sites
[code]
$sql3 = mysql_query("INSERT INTO '$list1' (user_id, fullname) VALUES ('$userid', '$name')") or die (mysql_error());
[/code]
try putting quotes around $list1

Share this post


Link to post
Share on other sites
[!--quoteo(post=375327:date=May 19 2006, 04:09 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 19 2006, 04:09 PM) [snapback]375327[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]
$sql3 = mysql_query("INSERT INTO '$list1' (user_id, fullname) VALUES ('$userid', '$name')") or die (mysql_error());
[/code]
try putting quotes around $list1
[/quote]

I already tried that. I get this 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 ''' (user_id, fullname) VALUES ('1121', 'Jeff Gordon')'

thanks tho

Share this post


Link to post
Share on other sites
echo $list1;

see if it is holding the correct table name (including spelling).

then also make sure that user_id and fullname are the correct column names (including spelling), and also they correct data types for what you are trying to insert. user_id should at least be an int and fullname should at least be a varchar

Share this post


Link to post
Share on other sites
Ok i got the solution, thanks for the help guys

turns out it was a session problem:

session_register('list1');
$_SESSION['list1']=$list1;

i commented out the $_SESSION line... i didnt think i needed it, guess i do. thanks

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.