Struggling to Insert Data with DBConnect

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
NickD
Pro Scripter
Posts: 58
Joined: Fri Sep 23, 2016 2:17 pm

Struggling to Insert Data with DBConnect

Post by NickD » Sun Aug 27, 2017 10:57 am

I am trying to use a MySQL database to store data created in a dialog macro I wrote. I can connect to the database, but when I try to INSERT, I get an error telling me that a parameter object in the DBExec line is improperly defined.

Code: Select all

Let>MySQLTable=PostContent
Let>MySQLServer=xxx.xxx.xx.xx
Let>MySQLPort=3306
Let>MySQLUser=username
Let>MySQLPassword=password
Let>MySQLDatabase=databasename
Let>ODBCDriver=MySQL ODBC 5.3 Unicode Driver
Let>MySQLPort=3306
Let>ConnectionString=Driver{%ODBCDriver%};Server=%MySQLServer%;Port=%MySQLPort%;Database=%MySQLDatabase%;Uid=%MySQLUser%;Pwd=%MySQLPassword%;


Let>SQLCmd=INSERT INTO %MySQLTable% (title,image1,image1_link,image1_description,image2,image2_link,image2_description,image3,image3_link,image3_description,image4,image4_link,image4_description,tags,published,account) values ("%Title%","%Image1SRC%","%ImageLink1%","%Description1%","%Image2SRC%","%ImageLink2%","%Description2%","%Image3SRC%","%ImageLink3%","%Description3%","%Image4SRC%","%ImageLink4%","%Description4%","%Tag%","%Published%","%Account%")


DBConnect>ConnectionString,dbH
DBExec>dbH,SQLCmd,result
DBClose>dbH

User avatar
Djek
Pro Scripter
Posts: 147
Joined: Sat Feb 05, 2005 11:35 pm
Location: Holland
Contact:

Re: Struggling to Insert Data with DBConnect

Post by Djek » Mon Aug 28, 2017 8:31 am

hi Nick,
does an UPDATE statement work?

Sometimes you must use a single quote instead of double quotes, so
('%Title%','%Image1SRC%','%ImageLink1%' etc

kind regards,
Djek

NickD
Pro Scripter
Posts: 58
Joined: Fri Sep 23, 2016 2:17 pm

Re: Struggling to Insert Data with DBConnect

Post by NickD » Mon Aug 28, 2017 1:13 pm

Hi Djek,

It was the double quotes, working fine now thanks :)

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts