Connecting works, I get the connectionID and so on, its just that I get this error:

I was wondering how I can resolve this to enter the data to the database?
Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller
Code: Select all
on insertRecord
//Setup colums that the data will be inserted to
put "clientName, clientEmail, clientNumber, jobDesc, postedBy, clientCompany" into dbCollumn // not variable names, just the collumns of db
//
//Setup the SQL command
put "INSERT INTO " & dbTable & " (" & dbCollumn & ") VALUES (:1, :2, :3, :4, :5, :6)" into dbSQL //dbSQL stores this command
//
//Send the SQL command
revExecuteSQL connectionID, dbSQL, "clientName", "clientEmail", "clientNumber", " jobDesc", "poster", "clientCompany"
//
if the result is a number then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the result
end if
end insertRecord
Code: Select all
on insertRecord
put "Fred Flintstone" into SQLArray[1]
put "myemail@fred.com" into SQLArray[2]
put "123" into SQLArray[3]
put "Programmer" into SQLArray[4]
put "Bettey Flintstone" into SQLArray[5]
put "Big Business" into SQLArray[6]
get executeSQL("BEGIN")
if it is not an integer then
-- error handling code
answer "An error occured BEGIN"
exit insertRecord
end if
put "INSERT INTO " & dbTable & "(clientName, clientEmail, clientNumber, jobDesc, postedBy, clientCompany "&\
"VALUES (:1,:2,:3,:4,:5,:6)" into dbSQL
revExecuteSQL connectionID, dbSQL, "SQLArray"
if the result is not an integer then
get executeSQL("ROLLBACK")
-- error handling here
answer "An error occured ROLLBACK"
exit insertRecord
end if
get executeSQL("COMMIT")
if the result is a number then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the result
end if
end insertRecord
Code: Select all
function executeSQL psql,pparm
if pparm is empty then
revExecuteSQL the uDatabaseID of this stack, psql
else
revExecuteSQL the uDatabaseID of this stack, psql,"pparm"
end if
return the result
end executeSQL
Thanks for replying. I think I understand the first piece of code. Could you explain the second piece that goes in the Stack script? I'm a little confused at that.quailcreek wrote:I've learned from some of the best here on the forum. I suggest using this kind of set up. The values that are put into the array can be variables. I'm more of an SQLite user but this should work for MYSQL too.
This should go into your stack script.Code: Select all
on insertRecord put "Fred Flintstone" into SQLArray[1] put "myemail@fred.com" into SQLArray[2] put "123" into SQLArray[3] put "Programmer" into SQLArray[4] put "Bettey Flintstone" into SQLArray[5] put "Big Business" into SQLArray[6] get executeSQL("BEGIN") if it is not an integer then -- error handling code answer "An error occured BEGIN" exit insertRecord end if put "INSERT INTO " & dbTable & "(clientName, clientEmail, clientNumber, jobDesc, postedBy, clientCompany "&\ "VALUES (:1,:2,:3,:4,:5,:6)" into dbSQL revExecuteSQL connectionID, dbSQL, "SQLArray" if the result is not an integer then get executeSQL("ROLLBACK") -- error handling here answer "An error occured ROLLBACK" exit insertRecord end if get executeSQL("COMMIT") if the result is a number then answer info "New record added." else answer error "There was a problem adding the record to the database:" & cr & the result end if end insertRecord
Code: Select all
function executeSQL psql,pparm if pparm is empty then revExecuteSQL the uDatabaseID of this stack, psql else revExecuteSQL the uDatabaseID of this stack, psql,"pparm" end if return the result end executeSQL
Code: Select all
function executeSQL psql,pparm
if pparm is empty then
revExecuteSQL connectionID, psql
else
revExecuteSQL connectionID, psql,"pparm"
end if
return the result
end executeSQL
Code: Select all
on insertRecord
-- Put the contents of the fields into SQLarray
put field "clientName" into SQLarray[1]
put field "clientEmail" into SQLarray[2]
put field "clientNumber" into SQLarray[3]
put field "jobDesc" into SQLarray[4]
put field "poster" into SQLarray[5]
put field "clientCompany" into SQLarray[6]
//
get executeSQL("BEGIN")
if it is not an integer then
answer "An error occured BEGIN"
exit insertRecord
end if
//
//
put "INSERT INTO " & dbTable & " (clientName, clientEmail, clientNumber, jobDesc, postedBy, clientCompany "&\
"VALUES (:1,:2,:3,:4,:5,:6)" into dbSQL
revExecuteSQL connectionID, dbSQL, "SQLarray"
//
if the result is not an integer then
get executeSQL("ROLLBACK")
answer "An error occured ROLLBACK"
exit insertRecord
end if
//
//
get executeSQL("COMMIT")
if the result is a number then
answer info "New record added."
else
answer error "There was a problem adding the record to the database:" & cr & the result
end if
end insertRecord
Code: Select all
put "INSERT INTO " & dbTable & "(clientName, clientEmail, clientNumber, jobDesc, postedBy, clientCompany) "&\