MySQL Trigger promlem

by 7 replies
9
I'm pulling my hair out over this. Anyone have any ideas?

Code:
DELIMITER $$
CREATE TRIGGER `update_features` AFTER INSERT ON `jos_cbsubs_plans` 
BEGIN
DECLARE itype varchar(16); 
SET itype := 'usersubscription';
IF NEW.item_type =  itype THEN  INSERT INTO jos_cbsubs_dya_subscription_features (subs_id,published) VALUES (NEW.id,NEW.published);
END IF; 
END $$
DELIMITER ;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'BEGIN
DECLARE itype varchar(16);
SET itype := 'usersubscription';
IF NEW.ite' at line 2
#programming #mysql #promlem #trigger
  • Hi, Lisa. Have you tried it without the variable declaration? You don't really need it, and I've found some posts here and there that report the same error when trying to declare variables inside a trigger. Not sure why, but in your case this is simpler anyway, isn't it?

    Code:
    DELIMITER $$
    CREATE TRIGGER `update_features` AFTER INSERT ON `jos_cbsubs_plans` 
    BEGIN
    IF NEW.item_type =  'usersubscription' THEN  INSERT INTO jos_cbsubs_dya_subscription_features (subs_id,published) VALUES (NEW.id,NEW.published);
    END IF; 
    END $$
    DELIMITER ;
    HTH.

    Steve
    • [ 2 ] Thanks
    • [1] reply
    • "IF NEW.item_type = 'usersubscription' "

      I tried that initially and it failed as well. I just posted it to ScriptLance and someone is fixing it for $8. Can't beat that. Thanks for your response.

      Lisa
      • [1] reply
  • I know diddley about coding, but I was able to follow some of this, and I have to agree with Lisa. Go figure.

Next Topics on Trending Feed

  • 9

    I'm pulling my hair out over this. Anyone have any ideas? Code: DELIMITER $$ CREATE TRIGGER `update_features` AFTER INSERT ON `jos_cbsubs_plans` BEGIN DECLARE itype varchar(16); SET itype := 'usersubscription'; IF NEW.item_type = itype THEN INSERT INTO jos_cbsubs_dya_subscription_features (subs_id,published) VALUES (NEW.id,NEW.published); END IF; END $$ DELIMITER ; MySQL said: Documentation