mysqltriggersphpmyadmin

Phpmyadmin doesn't accept MySQL trigger


I'm trying to create a trigger using Phpmyadmin, but my trigger keeps getting rejected.
Suppose having these tables:
table1 (Code, etc.)
table2 (Code, etc.)
table3 (Code, etc.)
table4 (Code, etc.)
table5 (table1Code, table3Code, table4Code)
table6 (table2Code, table4Code)
etc., but these are the ones I'm using in this trigger.

Here's the code:

DELIMITER //

CREATE TRIGGER newNews
AFTER INSERT
   ON News FOR EACH ROW
   
BEGIN
SET @table1 = (SELECT MAX(Code) FROM table1);
SET @table2 = (SELECT table2Code FROM table5 WHERE table1Code=@table1);
SET @table3 = (SELECT table3Code FROM table5 WHERE table1Code=@table1);
SET @table4 = (SELECT table2Code FROM table6 WHERE table2Code=@table2);
SET @i = 0;
WHILE @i < COUNT(@table4)
{
    INSERT INTO Inbox(a, b, c, d, e) VALUES (@cod, @i, @table4[i], "", CURDATE());
    i++;
}
END; //

DELIMITER ;

Phpmyadmin shows this message:

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 '{

INSERT INTO Inbox(a, b, c, d, e) VALUES (' at line 12

I don't understand what is the problem. Before pointing out that Date might get a conflict, it's just translated in english, in my language I use Data.


Solution

  • Sorry, but MySQL syntax doesn't have curly braces and your WHILE is missing the DO.

    Change your WHILE loop to

    WHILE @i < COUNT(@studs) DO
        INSERT INTO Inbox(Sender, Receiver, Object, Content, Date) VALUES (@cod, @i, @studs[i], "", CURDATE());
        @i = @i + 1;
    END WHILE; //