title: MySQL triggers check if insert is successfull or not
body: <p>As mentioned in the title, i have created a trigger that catches when a new value is inserted in the 'candidate' table, and stores some information in the table 'history'. However, i would also like to store if the insertion is successful or not, but cannt quite seem to get it to work. I have tried:</p>
  
  <pre><code>DELIMITER $$
  CREATE TRIGGER cand_i BEFORE INSERT ON candidate FOR EACH ROW
  BEGIN
  DECLARE action varchar(10);
  IF(EXISTS(select username from candidate where username=NEW.username)) THEN
      SET action='Failed';
  ELSE SET action='Success';
  END IF;
  INSERT INTO history (actiontype,actiondate,actionsuccess,actiontable,username)
  VALUES ('Insert',now(),action,'Candidate',NEW.username);
  END $$
  DELIMITER ;
  </code></pre>
  
  <p>Any suggestions?</p>