简体   繁体   English

如何创建触发器以将新用户详细信息插入到另一个表?

[英]How to create a trigger to insert new users details to another table?

Im trying to "synchronize" an external forum script (SMF) with my website. 我试图将一个外部论坛脚本(SMF)与我的网站“同步”。 Thats means, when a user registers in my website, a trigger insert the user details (username, password and email) in the external forum members table. 就是说,当用户在我的网站上注册时,触发器将在外部论坛成员表中插入用户详细信息(用户名,密码和电子邮件)。 Something like that, but its wrong, sql error. 那样的东西,但是它是错误的,sql错误。

CREATE TRIGGER forumReg 
AFTER INSERT ON hotaru_users 
FOR EACH ROW
BEGIN
    INSERT INTO forum_members (member_name, email_address, passwd)
    VALUES (NEW.user_username, NEW.user_email, NEW.user_password);
END

hotaru_users is my website users table, forum_members is the external forum users table, both tables are in the same mysql database hotaru_users是我的网站用户表,forum_members是外部论坛用户表,两个表都在同一个mysql数据库中

the error 错误

Erro

consulta SQL:

CREATE TRIGGER forumReg AFTER INSERT ON hotaru_users
FOR EACH
ROW
BEGIN
INSERT INTO forum_members( member_name, email_address, passwd )
VALUES (
NEW.user_username, NEW.user_email, NEW.user_password
);

Mensagens do MySQL : Documentação
#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 '' at line 6 

Either remove the BEGIN , END : 删除BEGINEND

CREATE TRIGGER forumReg 
AFTER INSERT ON hotaru_users 
FOR EACH ROW
    INSERT INTO forum_members (member_name, email_address, passwd)
    VALUES (NEW.user_username, NEW.user_email, NEW.user_password);

or change the delimiter for the creation of the trigger: 或更改用于创建触发器的定界符:

DELIMITER $$
CREATE TRIGGER forumReg 
AFTER INSERT ON hotaru_users 
FOR EACH ROW
BEGIN
    INSERT INTO forum_members (member_name, email_address, passwd)
    VALUES (NEW.user_username, NEW.user_email, NEW.user_password);
END 
$$
DELIMITER ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在插入另一个数据库的表上创建触发器 - How Do I create a trigger on a table that insert into another database 如何使用触发器插入另一个表? - how to insert into another table with a trigger? 如何在表格上创建插入触发器? - How to create insert trigger on table? 创建触发器将旧数据插入新表 - Create a trigger to insert the old data to a new table 创建触发器以在创建新行时将主键从一个表插入到 MySQL 中另一个表的列中 - Create trigger to insert primary key from one table upon creation of new row, into column of another table in MySQL Mysql-创建触发器以根据另一张表中插入的行插入新行 - Mysql - Create trigger to insert a new row based on a row inserted in another table 在插入后使用触发器创建新记录并从另一个表中选择 - Using Trigger to Create new records using after insert and select from another Table 使用触发器将新行从另一表插入到一个表? - Use trigger to INSERT new row to one table from another table? 如何创建将新行添加到另一个表并将对新行的引用添加到当前表的触发器? - How to create a trigger that adds a new row to another table and a reference to the new row added to present table? 在插入或更新后,如何创建MySQL触发器以使用来自另一个表中字段的数据更新表的总和 - How to create a MySQL trigger for updating a sum of a table with data from a field in another table after an on Insert or Update
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM