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 6616017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:31:57+00:00 2026-05-25T20:31:57+00:00

I am trying to bring together two separate designs here so I understand the

  • 0

I am trying to bring together two separate designs here so I understand the overall approach may not be ideal. Basically through user input in PHP table1 and part of table2 is populated and then in turn I need the rest of table2 and table3 to be populated automatically.

I have the following db

enter image description here

with this trigger

DELIMITER |

CREATE TRIGGER new_trigger AFTER INSERT on table2
FOR EACH ROW BEGIN
    INSERT INTO table3(att1, DateCreated, DateUpdated)
    VALUES('PG', now(), now());
    UPDATE table2 SET table3Id = table3.LAST_INSERT_ID();
END;
|

DELIMITER ;

although MySQL accepts the trigger as written without any errors I get this error when the app runs:

 General error: 1442 Can't update table 'table2' in stored function/trigger 
    because it is already used by statement which invoked this stored function/trigger

I believe this comes from MySQL triggers can’t manipulate the table they are assigned to. So if this is the reason for the error how else can I achieve the same results?

EDIT: (ANSWER)

Thanks to the help from mootinator here and in chat. Here is his solution that works as I need it to.

CREATE TRIGGER new_trigger BEFORE INSERT on table2
FOR EACH ROW BEGIN
    INSERT INTO table3(att1, DateCreated, DateUpdated)
    VALUES('PG', now(), now());
    SET NEW.table3Id = LAST_INSERT_ID();
END;
  • 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-05-25T20:31:58+00:00Added an answer on May 25, 2026 at 8:31 pm

    You can’t use an AFTER trigger because the new change you make would (potentially) cause the AFTER trigger to be run again in an infinite loop. You have to use a BEFORE trigger to edit the row before it gets written.

    Try eg:

    CREATE TRIGGER new_trigger BEFORE INSERT on table2
    FOR EACH ROW BEGIN
        INSERT INTO table3(att1, DateCreated, DateUpdated)
        VALUES('PG', now(), now());
        SET NEW.table3Id = LAST_INSERT_ID();
    END;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to mesh together two Jquery mobile plugins. Both are using the same
I'm trying to bring myself up to speed on C#, having never developed for
I'm trying to bring a legacy C# .NET 1.1 application into the modern era.
I'm trying to bring a C++ library into C#, so naturally I am trying
I am trying to put together a simple POC for a n-layer application using
Can anyone help me with a MySQL query I'm trying to put together. I
Does anyone have a good team building exercise to help bring together disparate teams
I'm trying to build a big static library merging two static libraries. In moment
I'm trying to count up ip addresses found in a log file on two
I am trying to Build a gallery in Android ( Not exactly what is

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.