Replace or delete then insert into

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Jordy
Posts: 32
Joined: Sat Feb 27, 2016 3:59 am

Replace or delete then insert into

Post by Jordy » Sun May 29, 2016 11:38 pm

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

Klaus
Posts: 13828
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Replace or delete then insert into

Post by Klaus » Mon May 30, 2016 4:51 pm

Hi Jordy,

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

Best

Klaus

Jordy
Posts: 32
Joined: Sat Feb 27, 2016 3:59 am

Re: Replace or delete then insert into

Post by Jordy » Mon May 30, 2016 8:30 pm

thats the help I needed thanks

Post Reply

Return to “Databases”