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
Problem in using INSERT in MySQL database
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Problem in using INSERT in MySQL database
Alex
Nice to meet all of you.
Nice to meet all of you.
-
- VIP Livecode Opensource Backer
- Posts: 56
- Joined: Sat Apr 08, 2006 5:28 pm
- Location: Eau Claire, WI
- Contact:
Re: Problem in using INSERT in MySQL database
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: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
put "INSERT INTO table_name (field1, field2) VALUES ('" & tname & "," & "'" & tage & "')" into theSQL
HTH,
Ken Ray
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com
Sons of Thunder Software
Email: kray@sonsothunder.com
Web site: http://www.sonsothunder.com