I have a html form that send some data in a database. I just created a trigger that on every people that complete the city field with LA will add the word "HI FROM LA" in a column named tag.
The problem is that after I created this trigger I get an error when I try to submit a form:
#1442 - Can't update table 'users' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
The trigger is:
DELIMITER |
CREATE TRIGGER update_tag BEFORE INSERT ON users
FOR EACH ROW
BEGIN
IF (NEW.city= 'LA') THEN
INSERT INTO users
SET NEW.tag = 'HI FROM LA';
END IF;
END;
|
DELIMITER ;
The insert is done with:
INSERT INTO users(id, name, city) VALUES(23, "John", "LA")
What alternatives do I have to avoid this conflict?
EDITED TRIGGER:
I also created a new table called 'trigger':
DELIMITER |
CREATE TRIGGER update_tag BEFORE INSERT ON users
FOR EACH ROW
BEGIN
IF (NEW.city= 'LA') THEN
INSERT INTO trigger
SET NEW.tag = 'HI FROM LA';
END IF;
END;
|
DELIMITER ;
With this trigger, I get an error on line 5