title: MySQL Trigger with conditional statement and update another table
body: <p>On MySQL 5.5, I am trying to write a trigger to do the following: </p>
  
  <ul>
  <li>Checks a condition for the insert (is group_id between 8-20?)</li>
  <li>If the condition is true, then update the user with the same user_id on <strong>another table</strong>, called phpbb_users. </li>
  <li>The update on this other table is to set user_rank to NEW.group_id from the insert on the table that has the trigger.</li>
  <li>Else, do nothing.</li>
  </ul>
  
  <p><strong>Not experienced at all, and stuck.</strong> It's not working when I run the query. Here is what I've got so far.</p>
  
  <pre><code>DELIMITER $$
  
      CREATE OR REPLACE TRIGGER upd_rank AFTER INSERT ON `phpbb_user_group`
      FOR EACH ROW BEGIN
        IF (NEW.group_id BETWEEN 8 AND 20) THEN
              UPDATE phpbb_users
              SET user_rank=NEW.group_id 
              WHERE user_id=NEW.user_id;
         ELSE 
              UPDATE phpbb_users
              SET user_rank='0'
              WHERE user_id=NEW.user_id;
         END IF;
      END$$;
  
  DELIMITER;
  </code></pre>
  
  <p>(Note, the "else" clause is unnecessary really - happy for any suggestions for improvement of this code!)</p>