1

I'm trying to write a very simple trigger for MySQL using phpmyadmin 4.0.8, what I want to do, is after a table called 'upload' is inserted into, I take the username, and id and put it into a second table called 'rating'

This is what I'm trying,

CREATE TRIGGER copy_pid AFTER INSERT on upload FOR EACH ROW BEGIN

INSERT INTO rating (uid,pid) VALUES (NEW.username,NEW.id);

END;

I get an "#1064 - You have an error in..."

1 Answer 1

1

MySQL is interpreting the semi-colon at the end of your INSERT statement as the end of the input. You need to change your delimiter while youe set up your trigger:

delimiter $$
CREATE TRIGGER copy_pid AFTER INSERT on upload FOR EACH ROW 

BEGIN

INSERT INTO rating (uid,pid) VALUES (NEW.username,NEW.id);

END$$
delimiter ;
Sign up to request clarification or add additional context in comments.

4 Comments

That does fix it! But... now when I insert into upload nothing ends up in the table
This is what I'm doing now "DELIMITER // DROP TRIGGER IF EXISTS copy_pid // CREATE TRIGGER copy_pid AFTER INSERT on sc_main.upload FOR EACH ROW BEGIN INSERT INTO sc_main.rating (uid, pid) VALUES (NEW.username, NEW.id); END"
I didn't look at what your trigger was actually doing. Does your new code do what you need?
no, it just stops my from inserting into the table the this triggers on. But it did answer my syntax error I was wondering about

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.