tomdchi Posted January 7, 2010 Share Posted January 7, 2010 I have never needed to use triggers before but now I do but I am just now learning the correct syntax. I keep getting the eror below when I try to create this trigger. Can someone spot the problem? #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 '' at line 6 table and trigger: CREATE TABLE IF NOT EXISTS `tblaccounts` ( `id` int(10) NOT NULL auto_increment, `userid` int(10) NOT NULL, `currency` int(10) NOT NULL, `gateway` varchar(30) NOT NULL, `date` datetime default NULL, `description` varchar(100) NOT NULL, `amountin` decimal(10,2) NOT NULL default '0.00', `fees` decimal(10,2) NOT NULL default '0.00', `creditapplied` decimal(10,2) default NULL, `rate` decimal(10,5) NOT NULL default '1.00000', `transid` varchar(30) default NULL, `invoiceid` int(10) NOT NULL default '0', `refundid` varchar(30) default '0', `fundingid` varchar(30) default NULL, `fundingdate` date default NULL, `processed` tinyint(1) NOT NULL default '1', `statusid` int(10) default '0', PRIMARY KEY (`id`), KEY `invoiceid` (`invoiceid`), KEY `userid` (`userid`), KEY `transid` (`transid`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; DELIMITER | CREATE TRIGGER creditapplied BEFORE UPDATE ON tblinvoices FOR EACH ROW BEGIN IF NEW.credit != OLD.credit THEN INSERT INTO tblaccounts SET userid = OLD.userid, gateway = OLD.paymentmethod, date = NOW( ) , description = 'Invoice Payment', creditapplied = NEW.credit, invoiceid = OLD.id, processed = 2; END; | DELIMITER; Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/ Share on other sites More sharing options...
tomdchi Posted January 8, 2010 Author Share Posted January 8, 2010 Anyone?? Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/#findComment-991292 Share on other sites More sharing options...
Mchl Posted January 8, 2010 Share Posted January 8, 2010 Are you running these queries at once, or one after another? In other words: should I look at line 6 in CREATE TABLE or at CREATE TRIGGER? Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/#findComment-991307 Share on other sites More sharing options...
tomdchi Posted January 8, 2010 Author Share Posted January 8, 2010 Oh, im sorry line 6 on trigger. Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/#findComment-991311 Share on other sites More sharing options...
Mchl Posted January 8, 2010 Share Posted January 8, 2010 Try: DELIMITER | CREATE TRIGGER creditapplied BEFORE UPDATE ON tblinvoices FOR EACH ROW BEGIN IF NEW.credit != OLD.credit THEN INSERT INTO tblaccounts SET userid = OLD.userid, gateway = OLD.paymentmethod, date = NOW( ) , description = 'Invoice Payment', creditapplied = NEW.credit, invoiceid = OLD.id, processed = 2; END IF; /*IF requires END IF*/ END; | DELIMITER; Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/#findComment-991314 Share on other sites More sharing options...
tomdchi Posted January 8, 2010 Author Share Posted January 8, 2010 That was it!! Thank you soooo much. Link to comment https://forums.phpfreaks.com/topic/187537-please-help-with-trigger-syntax-error/#findComment-991356 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.