Reputation: 137
I want to create a Trigger which should update the particular record of the table. for example
From Backend
Suppose I have a table called Video and it is having one column called Link, where I will be putting the links of the websites like www.google.com
From front end I have a Form where the user will fill the form and enter the website address in one text field and will submit, then on submit, same website address is going to update in the Video table in database and new record is created.
Now, I want to create a Trigger whenever the new record is updated in the table video, I want to change the value of link, by enclosing the link inside <iframe>
.
example if user is entering the www.google.com
in Form from frontend and submits, the value (www.google.com)
will go to database and as soon as it enters the database, its value should change from www.google.com
to <iframe src = "https://www.google.com">
by using trigger.
Which I am not able to do, I have tried many options available on the net. but no success.Pl help how to create this trigger
CREATE TRIGGER ins_sum AFTER INSERT ON video
FOR ROW WHERE ID = (SELECT max(ID) FROM video) SET embed_code = embed_code + "Test";
It is giving error
The following query has failed: "CREATE TRIGGER `frame` BEFORE INSERT ON `video` FOR EACH ROW CREATE TRIGGER ins_sum AFTER INSERT ON video FOR ROW WHERE VID = (SELECT max(VID) FROM video) SET embed_code = embed_code + "Test";"
MySQL said: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ROW WHERE VID = (SELECT max(VID) FROM video) SET embed_code = embed_code + "T...' at line 1
Thanks
Upvotes: 0
Views: 90
Reputation: 49410
As shown in my provided Link we havve to know tghe ect layout of all the tables, at least the relevant parts.
but i think you are looking for such an trigger
DELIMITER $$
CREATE TRIGGER after_LINK_insert
AFTER INSERT
ON video FOR EACH ROW
BEGIN
UPDATE LINK SET VIDEO = CONCAT('<iframe src = "',NEW.LINL,'" ...att />') WHERE ID = NEW.ID;
END$$
DELIMITER ;
The DELIMITER are needed if you add the trogger in a Query window.
Upvotes: 1