Page 1 of 1

Replace or delete then insert into

Posted: Sun May 29, 2016 11:38 pm
by Jordy
Hello I am accessing and manipulating a mysql DB based on this tutorial

http://lessons.livecode.com/m/4071/l/70 ... l-database


This is how I have been adding records

on mouseUp

-- check the global connection ID to make sure we have a database connection

global gConnectionID

if gConnectionID is not a number then

answer error "Please connect to the database first."

exit to top

end if


-- edit these variables to match your database & table

-- this assumes a table called Table1 with 3 fields

put "Table1" into tTableName



put "INSERT INTO " & tTableName & " (" & tFields & ") VALUES (:1)" into tSQL


-- send the SQL to the database, filling in the placeholders with data from variables

revExecuteSQL gConnectionID, tSQL, "tFirstName", "tLastName", "tBirthDate"


-- check the result and display the data or an error message

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 mouseUp


I would like to replace for edit the record instead of adding a new one.
Any suggestions would be great

Re: Replace or delete then insert into

Posted: Mon May 30, 2016 4:51 pm
by Klaus
Hi Jordy,

"update" is the SQL command you are looking for:
http://www.w3schools.com/sql/sql_update.asp

Best

Klaus

Re: Replace or delete then insert into

Posted: Mon May 30, 2016 8:30 pm
by Jordy
thats the help I needed thanks