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
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
Link to comment
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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.