Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Crazylife's avatar

How to use triggers for logging history of database changes by which user in phpmyadmin?

This is my trigger code to log changes when quantity has been made changes.

CREATE TRIGGER `qty_chgs` AFTER UPDATE ON `cart`
    FOR EACH ROW BEGIN
    IF NEW.QUANTITY != OLD.QUANTITY THEN
    INSERT INTO logs (`action`,`product_id`,`created_at`,`updated_at`) VALUES (1,NEW.PRODUCT_ID,CURRENT_TIMESTAMP,CURRENT_TIMESTAMP);
    END IF;
END

I have a table named 'users'. When the quantity amount in 'cart' table being modified, j want to log the user id and also the product id. How can i track which user modified it?

0 likes
1 reply
Cronix's avatar

The only way you could is if your cart table contained those fields.

Please or to participate in this conversation.