user140102
user140102

Reputation: 135

Trigger don't work

Need some help here :)

 DELIMITER |
    CREATE TRIGGER update_tab2 AFTER INSERT ON contacts
        FOR EACH ROW
                BEGIN
                IF(NEW.city= 'LA') THEN
                    SET  NEW.tag = "HI LA";
                END IF;
            END;
     |
    DELIMITER ;

This trigger should update me the tag column when the user complete a html "city" form with LA. The trigger is correct (the syntax I mean, but just don't put anything in the "tag" column.

Can anyone give me a hint about what is wrong? :)

Upvotes: 1

Views: 77

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

You need a before insert trigger if you want to change the data being inserted:

DELIMITER |
CREATE TRIGGER update_tab2 BEFORE INSERT ON contacts
    FOR EACH ROW
            BEGIN
            IF(NEW.city = 'LA') THEN
                SET  NEW.tag = "HI LA";
            END IF;
        END;
 |
DELIMITER ;

Upvotes: 2

Related Questions