Page 1 of 1
Delete entries in mysql database
Posted: Sat Oct 29, 2011 10:41 pm
by rayck23
Hi, sorry if this has been covered but I am having issues finding a solution. I want users to be able to delete the entries that have been compiled in a database table I have created by clicking a button. I have been able to allow users to make entries into the database table, but cannot seem to get the coding correct so they can clear it. I have tried following help section, but am unsure where to put the command in my code. Thanks for the help!
This is what my code looks like for the button, I know this is not correct because this is the "Add record" code....
This is what I am trying to do.....
And for deleting:
DELETE FROM Table1 WHERE firstName='Mary' AND lastName='Smith'
Then use revExecuteSQL and check for errors as before.
Re: Delete entries in mysql database
Posted: Sun Oct 30, 2011 9:21 am
by bangkok
I'm not sure to understand correctly what is your problem...
Anyway.
put "DELETE FROM Table1 WHERE firstName='Mary' AND lastName='Smith' " into tySQL
revExecuteSQL gConnectionID,tSQL
if the result is a not a number then
answer "Error : "&the result
else
answer "ok"
end if
PS : i would avoid to use cap in tables and columns names.
Re: Delete entries in mysql database
Posted: Sun Oct 30, 2011 3:33 pm
by rayck23
I apologize for the confusion....I was in a rush when I wrote my question. Here we go....
I have a database called "slpproject" that has a table called "table1". I am able to create entries in that table but am having issues with creating a line of code that will allow me to delete all the entries that have been made in that table. I followed the directions in the example for creating an entry to a database here,
but I am having problems figuring out where to enter the "Delete From" portion of the code into the above example,
I am sorry again if this confuses anyone....I am very new to this and am reading all I can in order to learn Livecode....but I feel like a 1st grader trying to learn physics!
Re: Delete entries in mysql database
Posted: Sun Oct 30, 2011 9:15 pm
by sturgis
If i'm understanding correctly, you want to completely clear table "table1" of all entries.
If so, the insert example you give is more intricate than you need. The first paragraph at
http://dev.mysql.com/doc/refman/5.0/en/delete.html specifies how to delete all rows (no where clause)
Code: Select all
on MouseUp
global gConnectionID
if gConnectionID is not a number then
answer error "Please connect to the database first"
exit to top
end if
-- since you don't need a where clause, its really straight forward. No Where means all rows removed.
put "delete from table1" into tSQL
revExecuteSQL gConnectionID, tSQL
if the result is a number then
answer info "All rows deleted"
else
answer error "There was a problem clearing table1" & cr & the result
end if
end mouseUp
rayck23 wrote:I apologize for the confusion....I was in a rush when I wrote my question. Here we go....
I have a database called "slpproject" that has a table called "table1". I am able to create entries in that table but am having issues with creating a line of code that will allow me to delete all the entries that have been made in that table. I followed the directions in the example for creating an entry to a database here,
creating.PNG
but I am having problems figuring out where to enter the "Delete From" portion of the code into the above example,
delete.PNG
I am sorry again if this confuses anyone....I am very new to this and am reading all I can in order to learn Livecode....but I feel like a 1st grader trying to learn physics!
Re: Delete entries in mysql database
Posted: Mon Oct 31, 2011 12:50 am
by rayck23
THANK YOU!!!!!! Works great....just what I wanted it to do!!!
Re: Delete entries in mysql database
Posted: Mon Oct 31, 2011 12:32 pm
by Klaus
Hi rayck,
I would not hurt to take look here, this also got me started with SQL!
http://www.w3schools.com/sql/default.asp
Best
Klaus