Image courtesy of Gualberto107 at

I battled for ages to find the correct syntax to create a trigger in MySQL — the examples I could find were all to complex and I could not get any of them to work. Here is a quick little example that you should find really easy to follow.

I did this using HeidiSQL, but it should work in phpMyAdmin. Firstly, create two tables:

When a new User is added to the tblUsers table, the userID of that new User must be recorded in the tblUsersLog table along with the date on which the User was created.

  1. select the relevant database
  2. go to the SQL tab in phpMyAdmin, or the Query tab in HeidiSQL
  3. enter the following statement and click GO in phpMyAdmin or Run in HeidiSQL to execute the statement and create the TRIGGER
To test your TRIGGER, insert a new record into tblUsers:
and check out your tblUsersLog! It should have one new record in it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.