title: Mysql Trigger with condition and calculations
body: <p>Im using mysql trigger to insert <strong>contribution</strong> from <strong>After insert task table</strong> i need to calculate total hours (<strong>total_hours = new.hours + new. overtime</strong>) and i need to select total_hours from <strong>contribution</strong> table </p>
  
  <p>This is mysql trigger im using but its not working </p>
  
  <pre><code>     CREATE TRIGGER update_hours AFTER INSERT ON tasks
       FOR EACH ROW 
       BEGIN
       SELECT p_id d_id hours overtime total_hours FROM contribution WHERE 
        p_id == new.p_id &amp;&amp; d_id == new.d_id 
  
       new.total_hours = total_hours + new.hours + new.overtime
  
  
   INSERT INTO contribution
        ( p_id,
         d_id,
         hours,
         overtime,
         total_hours,
         contribution )
         VALUES
            ( NEW.p_id,
              NEW.d_id,
              NEW.hours,
              NEW.overtime,
              new.total_hours,
              NEW.contribution );
        END IF;
  
   END
  </code></pre>
  
  <p>i need to get values form contribution table and add there values to hours and overtime </p>
  
  <p>I need to insert to the contribution table when add a task hours and overtime. need to calculate total hours (hours + overtime) and add to contribution total_hours . </p>