NME Posted May 19, 2006 Share Posted May 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/ Share on other sites More sharing options...
.josh Posted May 19, 2006 Share Posted May 19, 2006 [code]$sql3 = mysql_query("INSERT INTO '$list1' (user_id, fullname) VALUES ('$userid', '$name')") or die (mysql_error());[/code]try putting quotes around $list1 Quote Link to comment https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/#findComment-37257 Share on other sites More sharing options...
NME Posted May 19, 2006 Author Share Posted May 19, 2006 [!--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 Quote Link to comment https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/#findComment-37259 Share on other sites More sharing options...
.josh Posted May 19, 2006 Share Posted May 19, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/#findComment-37261 Share on other sites More sharing options...
NME Posted May 19, 2006 Author Share Posted May 19, 2006 Ok i got the solution, thanks for the help guysturns 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 Quote Link to comment https://forums.phpfreaks.com/topic/10031-using-variables-for-table-names-sql/#findComment-37267 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.