0
CREATE TRIGGER leave_trigger
 AFTER INSERT ON leaveapplication
 FOR EACH ROW
 IF employeemaster.empcode='".$empcode."' THEN
 UPDATE employeemaster SET '".$leave_type=$leave_type."'-$numberofleave //I am facing problem here
 END IF;

Please help me correcting it syntactically GIVEN $leave_type is varchar and $numberofleave is integer.

2 Answers 2

1

You need save the field name in a different var

UPDATE employeemaster SET '".$fieldName."=".$leave_type."'-$numberofleave
Sign up to request clarification or add additional context in comments.

Comments

0

I am a little confused with what you are trying to do. Are you trying to create a trigger that will automatically do the following query?

UPDATE 
    employeemaster 
        SET leave_type=leave_type-".$numberofleave." 
        where empcode='".$empcode."'

Then I think you want to write the trigger as this:

CREATE TRIGGER leave_trigger
    AFTER INSERT ON leaveapplication
    FOR EACH ROW
        UPDATE employeemaster SET leave_type=leave_type-NEW.numberofleave where empCode=NEW.empCode
    END;

In the trigger, you don't want to use any variables from PHP with specifics. You want to insert the data into one table (leaveApplication) and then have the trigger use the data in that table to update the employeemaster. If you hardcode the data in the trigger, you will either need to create a trigger for every row of data in the employeemaster or the trigger won't work as expected.

1 Comment

@Aragorn Can you give this a whirl? I am guessing at some column names though, so you might want to adapt to your actual names.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.