WillyTheFish Posted February 2, 2010 Share Posted February 2, 2010 Hey Guys, i googles my a*s off and tried all different kinds of syntax combinations but this won't work: mysql_query("INSERT INTO `".$db_tablename."` `".$test1."`VALUES `".$test2."`"); where the var_dump for $test1 and $test2 is string(82) "(Article_Number,[iGNORE],Quantity Discount_1_-_Price,Quantity Discount_1_-_Amount)" string(39) "(120235,01.01.2010,+359.95 ,+299.95)" so basically i want to inset the data in $test2 into the field(s) $test1... please help! thanks! Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/ Share on other sites More sharing options...
gwolgamott Posted February 2, 2010 Share Posted February 2, 2010 do some error checking to make sure that your $test2 variable is actually the same as the field name in your database. It may just be something simple as variable having an extra character or case sensitive issue. EDIT: I mean that you seem to be doing it right and that it may be another issue instead. Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/#findComment-1005480 Share on other sites More sharing options...
onlyican Posted February 2, 2010 Share Posted February 2, 2010 A good method I use to debug Edit code to be something like $strSql = "INSERT INTO `".$db_tablename."` `".$test1."`VALUES `".$test2."`"; mysql_query($strSql); echo "Query was ".$strSql."<br />".Error is ".mysql_error(); Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/#findComment-1005485 Share on other sites More sharing options...
WillyTheFish Posted February 2, 2010 Author Share Posted February 2, 2010 thanks guys, almost got it figured out now.... mysql_query("INSERT INTO `".$db_tablename."` ".$test1." VALUES ".$test2.""); $test2 contains the string: (123456', '12,45', '10', '11,45', 'Buy me!') my error msg: 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 '', '12,45', '10', '11,45', 'Don't Buy me)' at line 1(654321', '10,11', '90', '9,11', 'Buy Me!) so i figured the error must have something to do with the format at '12,45' ... how do i make mysql swallow it? Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/#findComment-1005639 Share on other sites More sharing options...
wildteen88 Posted February 2, 2010 Share Posted February 2, 2010 $test2 contains the string: (123456', '12,45', '10', '11,45', 'Buy me!') You're missing a quote ('123456', '12,45', '10', '11,45', 'Buy me!') Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/#findComment-1005641 Share on other sites More sharing options...
WillyTheFish Posted February 2, 2010 Author Share Posted February 2, 2010 daaaamn i'm stupid sometimes thanks alot work's fine now! Quote Link to comment https://forums.phpfreaks.com/topic/190657-mysql-query-problem-how-do-i-insert-data-into-columns-defined-by-variables/#findComment-1005646 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.