title: MySQL After Insert Trigger Not Working
body: <p>I have the following two tables, and a trigger which should insert a record into the Student table when a record is inserted into the User table with a non-null value in StudentID.  MySQL reports no syntax errors on the trigger and an insert into the User table works as expected, but does not trigger an insert into the Student table.<br>
  I have tried using BEFORE and AFTER INSERT to no effect.  I am using phpMyAdmin version 3.5.2.2.  Any help would be greatly appreciated.</p>
  
  <pre><code>DROP TABLE IF EXISTS `User` ;
  
  CREATE  TABLE IF NOT EXISTS `User` (
    `UserID` INT NOT NULL AUTO_INCREMENT ,
    `FirstName` VARCHAR(45) NOT NULL ,
    `LastName` VARCHAR(45) NOT NULL ,
    `eMail` VARCHAR(60) NOT NULL ,
    `StudentID` INT NULL ,
    KEY ix_User_StudentID (StudentID),
    PRIMARY KEY (`UserID`)
  )
  ENGINE = InnoDB;  
  
  DROP TABLE IF EXISTS `Student` ;
  
  CREATE  TABLE IF NOT EXISTS `Student` (
    `StudentID` INT NOT NULL ,
    `UserID` INT NOT NULL ,
    PRIMARY KEY (`StudentID`) ,
    CONSTRAINT `fk_Student_User1`
      FOREIGN KEY (`StudentID` )
      REFERENCES `User` (`StudentID` )
      ON DELETE CASCADE
      ON UPDATE CASCADE, 
    CONSTRAINT `fk_Student_User2`
      FOREIGN KEY (`UserID`)
      REFERENCES `User` (`UserID`)
      ON DELETE CASCADE
      ON UPDATE CASCADE
  )
  ENGINE = InnoDB;
  
  DROP TRIGGER IF EXISTS after_insert_user;
  
  DELIMITER //
  CREATE TRIGGER after_insert_user 
  AFTER INSERT ON `User`
  FOR EACH ROW BEGIN
      IF (NEW.StudentID &lt;&gt; NULL) THEN
          INSERT INTO Student VALUES (NEW.StudentID, NEW.UserID); 
      END IF;
  END;
  //
  
  DELIMITER ;
  </code></pre>