Page 1 of 1

Problem in using INSERT in MySQL database

Posted: Thu May 04, 2006 11:06 am
by alex298
Hello,

I have problem in using INSERT in MySQL database.

It works for string and constant:

put "INSERT INTO table_name (field1, field2) VALUES ('Peter', 35)" into theSQL

However when I use variables like the following, it does not work:

Put "Peter" into tname
Put "35" into tage
put "INSERT INTO table_name (field1, field2) VALUES (tname, tage)" into theSQL

The query is success. However no data is inserted into the table.

Please help!

Thanks and best regards

Re: Problem in using INSERT in MySQL database

Posted: Thu May 04, 2006 4:17 pm
by kray
alex298 wrote:However when I use variables like the following, it does not work:

Put "Peter" into tname
Put "35" into tage
put "INSERT INTO table_name (field1, field2) VALUES (tname, tage)" into theSQL
You need to build your string with the variables appended - they won't automatically be translated because they appear in a string. Additionally, you'll need to make sure your variables are surrounded in single quotes. So you'll need to do it this way:

put "INSERT INTO table_name (field1, field2) VALUES ('" & tname & "," & "'" & tage & "')" into theSQL

HTH,