i have build a small website with a user login system. I want it so that when user logs in the 'UserThisLogin' value is being updated automatically but prior to that i want the value of the 'UserThisLogin' to be coppied into the 'UserLastLogin' field in the same row so that each user can keep track of when they were last logged in.
i have tried with a trigger but i cant seem to find the solution.
any help would be appreciated.
below are the sql used for the user table and the little i have of a trigger
CREATE Table User (
UserID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName VARCHAR(20) UNIQUE NOT NULL,
UserEmail varchar(35) DEFAULT NULL,
UserPassword varchar(50) NOT NULL,
UserApproved INT DEFAULT 0,
UserCreated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
UserThisLogin TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
UserLastLogin TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
UserLoginCount INT DEFAULT '0',
UserLevelID INT REFERENCES UserLevel(UserLevelID)
);
CREATE TRIGGER nywebdb.login_trigger
BEFORE UPDATE
ON nywebdb.User
AS
BEGIN
UPDATE User SET UserLastLogin = SELECT UserThisLogin FROM User where ;
END;