multiple Insert 'at same time'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nathanwb
    New Member
    • Mar 2008
    • 39

    multiple Insert 'at same time'

    When inserting data, can you insert parts of the form data into two different tables at the same time?
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    Yes. Just have two different MySQL statements in the file that the data is sent to:

    [CODE=mysql]
    mysql_query("IN SERT INTO table1 (var_a, var_b) VALUES($val_a, $val_c ) ")
    or die(mysql_error ());

    mysql_query("IN SERT INTO table2 (var_d, var_e) VALUES($val_b, $val_c ) ")
    or die(mysql_error ());
    [/CODE]

    There might be a quicker way, but that's one way.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      Originally posted by nathanwb
      When inserting data, can you insert parts of the form data into two different tables at the same time?
      When you mean by "at the same time" in "at the same time in real time", the answer is NO. These INSERT statements will be executed consecutively. When the second INSERT fails you have to make some code to retract the first one from the database.

      Another way is to include these statements in a "transactio n" where by you can commit (or rollback) a number of separate commands. See therefore MySQL documentation chapter Transaction model

      Ronald

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        This is a MySQL question/problem. I will move the thread to the MySQL forum.

        moderator

        Comment

        Working...