MySQL Forums
Forum List  »  Triggers

Re: Syntax error in trigger
Posted by: Gabriella Pepe
Date: August 13, 2017 12:35AM

Sorry for the previous post, this is the entire code (see comment):

DELIMITER //

CREATE TRIGGER onNewRow

AFTER INSERT
ON wp_postmeta FOR EACH ROW

BEGIN

DECLARE current_id bigint(20);
DECLARE mail_address varchar(100);
DECLARE user_id bigint(20);

-- here I'm hoping post_id is the post_id related to the new inserted row
-- I don't know if this is wrong
SET current_id = post_id;

SET mail_address = (SELECT meta_value FROM wp_postmeta WHERE post_id = current_id AND meta_key = "_from_email");

SET user_id = (SELECT ID FROM wp_users WHERE user_email = mail_address);

-- I don't know if this query could be assigned to a variable too
-- I don't know how to assign its type (*)
IF(exists(SELECT * FROM wp_posts WHERE ID = current_id AND post_type = "inbound" AND post_title IN ("Website feedback","General contact form")) THEN UPDATE wp_posts SET post_author = user_id WHERE ID = current_id;

END IF;

END; //

DELIMITER ;

Options: ReplyQuote


Subject
Views
Written By
Posted
1948
August 11, 2017 03:37AM
752
August 11, 2017 10:57AM
946
August 12, 2017 02:47AM
757
August 12, 2017 07:49AM
931
August 13, 2017 12:15AM
Re: Syntax error in trigger
978
August 13, 2017 12:35AM
947
August 13, 2017 11:09AM
821
August 14, 2017 05:47AM
815
August 14, 2017 10:17AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.