Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9257229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:08:13+00:00 2026-06-18T12:08:13+00:00

I really hope someone can help me out with this as it’s been bugging

  • 0

I really hope someone can help me out with this as it’s been bugging me for days. I have an after insert trigger on my users table that inserts a record into an audit table after every insert. This works fine if i’m on the command line manually executing the insert statement. However, when my web form inserts into the table then all the values inserted into the audit table are nulls. I’m thinking maybe it’s a permission issue so i added the CURRENT_USER() and also USER() to the trigger to be inserted into the audit table. It’s showing that the trigger is being executed by the “admin” user, which is the owner of the trigger.

Here is my trigger:

DELIMITER ^^
CREATE TRIGGER UsersInsert AFTER INSERT ON Users
FOR EACH ROW
BEGIN

INSERT INTO `users_audit` (`username`, `address`, `email`)
VALUES
(USER(), NEW.address, NEW.email);

END
^^

This will insert the following in the audit table: admin@localhost, null, null

And here are the permissions for the admin user:

GRANT ALL PRIVILEGES ON `MyDB`.* TO 'admin'@'localhost' WITH GRANT OPTION

Like i said, it works perfectly from the mysql command line. But for some reason the “NEW” values are all nulls when executing from a web form.

Please help. Thanks in advance.

UPDATE on 2/6/2013:

I tried a similar trigger but with “AFTER UPDATE” and it worked correctly. So the issue is isolated to inserting. And that also proves that it’s no a permission problem.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:08:14+00:00Added an answer on June 18, 2026 at 12:08 pm

    Well, after creating different types of triggers and experimenting, i figured that the insert trigger might have been firing more than once for some reason, actually firing both insert and update triggers, and the last row always had nulls which was the only record being inserted. It’s really strange. So anyway, to get around this i changed my code to this and it’s working with no issues thus far:

    DELIMITER ^^
    
    CREATE TRIGGER UsersUpdate AFTER UPDATE ON users
    FOR EACH ROW
    BEGIN
    
    IF NEW.username IS NOT NULL THEN
    
    IF EXISTS (SELECT 1 FROM users_audit WHERE username = NEW.username) THEN
    UPDATE users_audit SET `username` = NEW.username,  `FirstName` = NEW.FirstName, `LastName` = NEW.LastName, `address` = NEW.address, `email` = NEW.email WHERE username = OLD.username;
    ELSE
    INSERT INTO users_audit (`username`, `FirstName`, `LastName`, `address`, `email`)
    VALUES (NEW.username, NEW.FirstName, NEW.LastName, NEW.address, NEW.email);
    END IF;
    
    END IF;
    
    END
    ^^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure this out for days. Hope someone can help.
I really hope someone can help on this because I'm learning cocoa and have
I really hope someone here can help out with this. I'm using Magento 1.6.1.0
I'm almost losing it, i really hope someone can help me out! I'm using
I have a really hard time understanding routes and I hope someone can help
Really hope someone can help me as I'm a bit stuck :S I have
I hope there is someone who can help me out here. I have found
I think I'm stuck and I really hope someone can help me out here.
I really hope you can help out here. I'm creating a theme for a
I am really stuck with an sql query... I hope someone can help shed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.