Q:

Whats wrong with my Mysql trigger - Syntax error thrown

When i execute this trigger it throws error as 
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END' at line 27
delimiter //

CREATE TRIGGER `after_tblgps_insert` AFTER INSERT ON `tbl_gps`
FOR EACH ROW BEGIN
DECLARE cab_meter_new VARCHAR(10);
DECLARE cab_cost_new VARCHAR(10);
DECLARE cab_meter_old VARCHAR(10);
DECLARE cab_cost_old VARCHAR(10);
DECLARE pr_pnr_no  VARCHAR(15);
DECLARE pr_dest_id  VARCHAR(15);

select NEW.gps_rs232,NEW.gps_cab_bus,gps_rs232,gps_cab_bus into @cab_meter_new,@cab_cost_new,@cab_meter_old,@cab_cost_old from tbl_gps where gps_imei = NEW.gps_imei order by gps_id asc limit 0,1;

IF @cab_meter_new = 1 and @cab_meter_old = 0 THEN
BEGIN
select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 13;
select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
update tbl_taxi set taxi_cur_status = 12,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
update tbl_booking set booking_status = 9 where booking_pnr_no = @pr_pnr_no;
END;
ELSE IF @cab_meter_new = 0 and @cab_meter_old = 1 THEN
BEGIN
select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 9;
select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
update tbl_taxi set taxi_cur_status = 10,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
update tbl_booking set booking_status = 8 where booking_pnr_no = @pr_pnr_no;
END;
END IF
END //
delimiter ;

A:

try this code
delimiter //

CREATE TRIGGER `after_tblgps_insert` AFTER INSERT ON `tbl_gps`
FOR EACH ROW BEGIN
DECLARE cab_meter_new VARCHAR(10);
DECLARE cab_cost_new VARCHAR(10);

    DECLARE cab_meter_old VARCHAR(10);
    DECLARE cab_cost_old VARCHAR(10);
    DECLARE pr_pnr_no  VARCHAR(15);
    DECLARE pr_dest_id  VARCHAR(15);

    select NEW.gps_rs232,NEW.gps_cab_bus,gps_rs232,gps_cab_bus into @cab_meter_new,@cab_cost_new,@cab_meter_old,@cab_cost_old from tbl_gps where gps_imei = NEW.gps_imei order by gps_id asc limit 0,1;

    IF @cab_meter_new = 1 and @cab_meter_old = 0 THEN
    BEGIN
    select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 13;
    select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
    update tbl_taxi set taxi_cur_status = 12,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
    update tbl_booking set booking_status = 9 where booking_pnr_no = @pr_pnr_no;
    END;
    END IF;
    IF @cab_meter_new = 0 and @cab_meter_old = 1 THEN//break IF into separate IF 
    BEGIN
    select `booking_pnr_no` into @pr_pnr_no from tbl_booking where booking_alloted_vehicle = (select taxi_id from tbl_taxi where taxi_imei = NEW.gps_imei ) AND booking_status = 9;
    select trip_dst_area_id into @pr_dest_no from tbl_trip where pnr_id = @pr_pnr_no order by trip_id desc limit 0,1;
    update tbl_taxi set taxi_cur_status = 10,taxi_cur_area = @pr_dest_no where taxi_id = NEW.gps_cab_bus;
    update tbl_booking set booking_status = 8 where booking_pnr_no = @pr_pnr_no;
    END;
    END IF;
    END; //
    delimiter ;

