Jump to content

mysql query problem: how do i insert data into columns defined by variables


WillyTheFish

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

 

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.