Skip to main content
The 2024 Developer Survey results are live! See the results

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    I am in need of inserting a row in the user_permission table as well along side the user table. How would i do that?
    – StealthRT
    Commented Aug 22, 2012 at 12:58
  • 1
    Updated my OP to better explain what i was looking to do.
    – StealthRT
    Commented Aug 22, 2012 at 13:06
  • 2
    @StealthRT You can't insert new rows into 2 tables without multiple statements, or a trigger on the first table. Commented Aug 22, 2012 at 13:07
  • 1
    I updated my OP again to reflect what i am thinking you mean by your post. Let me know if its correct. Would i need to run "update" between the 2 inserts?
    – StealthRT
    Commented Aug 22, 2012 at 13:11
  • 3
    @StealthRT Yes, just like that - but you must execute the second immediately after the first, or the value of LAST_INSERT_ID() will become invalid. The LAST_INSERT_ID() is connection dependent, so as long as these are executed sequentially on the same connection, you'll get the right value back. If any other inserts happen in between, you'll get the wrong value. Commented Aug 22, 2012 at 13:18