multiple insert inot mysql table commands

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    multiple insert inot mysql table commands

    Hii guys,
    I have 2 tables in which data exists of a same user like his table1:login details and table2: his further details . I have a form where in his both login and rest of details are collected. When i submit the form it needs to insert data in both the tables . Which is the best method to do it . insert into 1st table and if successful then insert into 2nd table ?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Yes, that is generally how you complete two tasks... first one, and then the other one :)

    If you need them both to be successful, or neither should remain, then you can use Transactions.

    Assuming you are using PHP as your front-end, you can not do that with the old MySQL extension.
    You will need the Improved MySQL Extension to use transactions. (See the examples for the mysqli::rollbac k method)

    Comment

    Working...