Jump to content

Please help with trigger syntax error


tomdchi

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.