PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] Phpmyadmin doesn't accept MySQL trigger

 February 01, 2022     mysql, phpmyadmin, triggers     No comments   

Issue

I'm trying to create a trigger using Phpmyadmin, but my trigger keeps getting rejected.
Suppose having these tables:
News (Code, etc.)
Student (Code, etc.)
Teacher (Code, etc.)
Courses (Code, etc.)
NewsList (NewsCode, TeacherCode, CourseCode)
StudsCoursesList (StudentCode, CourseCode)
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 @news = (SELECT MAX(Code) FROM News);
SET @course = (SELECT CourseCode FROM NewsList WHERE NewsCode=@news);
SET @cod = (SELECT TeacherCode FROM NewsList WHERE NewsCode=@news);
SET @studs = (SELECT StudentCode FROM StudsCoursesList WHERE Course=@course);
SET @i = 0;
WHILE @i < COUNT(@studs)
{
    INSERT INTO Inbox(Sender, Receiver, Object, Content, Date) VALUES (@cod, @i, @studs[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(Sender, Receiver, Object, Content, Date) 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; //


Answered By - Sarath Chandra
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing