Eutherpy
Eutherpy

Reputation: 4571

Error trying to create trigger in phpMyAdmin

I have the following trigger:

DELIMITER //
CREATE TRIGGER historyTrigger AFTER UPDATE ON Item
FOR EACH ROW
BEGIN
 if NEW.LocationId <=> OLD.LocationId or NEW.PersonId <=> OLD.PersonId THEN
insert into History values(null, old.Id, old.LocationId, new.LocationId, old.PersonId, new.PersonId, date(now()));
END IF;
END;//
DELIMITER ;

which worked correctly on my database.

However, when I try to create this same trigger in phpMyAdmin, I get a syntax error (#1064 - You have an error in your SQL syntax; ... near line 1) enter image description here

Edit:

Having seen some other questions and examples online, and following the advice in the comments, I only left the body of my trigger:

if NEW.LocationId <=> OLD.LocationId or NEW.PersonId <=> OLD.PersonId THEN
insert into history values(null, old.Id, old.LocationId, new.LocationId, old.PersonId, new.PersonId, date(now()));

but I am still getting the same error, at line 2.

Upvotes: 0

Views: 431

Answers (1)

Nigel Ren
Nigel Ren

Reputation: 57121

When you use the dialog to create a trigger in phpmyadmin, the wrapping bits of the create trigger... are added before applying the code. So remove the main parts and leave the

if NEW.LocationId <=> OLD.LocationId or NEW.PersonId <=> OLD.PersonId THEN
     insert into history values(null, old.Id, old.LocationId, new.LocationId, old.PersonId, new.PersonId, date(now()));
end if;

Upvotes: 1

Related Questions