Jump to content

Using variables for Table names SQL


NME

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
Link to comment
https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/
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
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

Archived

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

×
×
  • Create New...

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.