简体   繁体   中英

MYSQL Update Pending Approval

I have a website where approved users can update, insert and delete data from a table. All of the final changes, however, must be approved before they are made "live" in the original table. I want the data in the original table to be updated on a case by case basis. What is the best way to go about this from the database side? Is it going to be triggers? Procedures? Transactions?

Is there a way to have a trigger on the main table, whereby, when an update is made, it will appear in the trigger table and not effect the live table?

Currently, my trigger looks like this. It works but it is updating both tables.

 DELIMITER //
CREATE TRIGGER TEST_UPDATE
BEFORE UPDATE ON test for each row
BEGIN
INSERT INTO test_changes(PERSONID, LASTNAME, FIRSTNAME, ADDRESS, CITY, TIME)
VALUES(NEW.PERSONID, NEW.LASTNAME, NEW.FIRSTNAME, NEW.ADDRESS, NEW.CITY, NEW.TIME); 
END
//

I am assuming that the actual approval/rejection process will have to be done via an admin page on the website. From what I have read so far, MYSQL cannot prompt users for input.

Thanks!!

After reviewing this question, I realize I was asking for something that is directly possible with MySQL, at least not to my knowledge. What I ended up doing was creating a pending changes table and then displaying it in an HTML table. The "admin" then goes in and approves or deny changes which will then send the changes to the appropriate tables.

This could have been done in a round about way by using an active / inactive column and then displaying rows based on a column value as suggested above but it is more straightforward to just make two tables with the appropriate data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM