how can i insert into 2 table?

Discussion in 'PHP' started by baris22, Jan 11, 2009.

  1. #1
    hello,

    i need help to insert data into 2 table. this is the code i am using to insert into 1 table, how can i insert into 2 table?

    
    
    $query="INSERT INTO `file` VALUES ('', '9',
    '".$type."', '".$topic."')";
        mysql_query($query);
        echo mysql_error();
        $c++;
       }
      }
      echo '<center><b>'. $c.' entries put into database</b></center><br/>';
      mysql_close($link);
     }
    
    
    PHP:
    thanks
     
    baris22, Jan 11, 2009 IP
  2. baris22

    baris22 Active Member

    Messages:
    543
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #2
    ok. never mind, sorted.
     
    baris22, Jan 11, 2009 IP
  3. shotazi

    shotazi Peon

    Messages:
    422
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i think you need another query
     
    shotazi, Jan 11, 2009 IP
  4. elias_sorensen

    elias_sorensen Well-Known Member

    Messages:
    852
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    110
    #4
    I do actually think you can use INSERT INTO table,table2 (xxxx..... if you have the same rows in the table.
     
    elias_sorensen, Jan 12, 2009 IP
  5. linkexchange1984

    linkexchange1984 Peon

    Messages:
    73
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    linkexchange1984, Jan 13, 2009 IP
  6. khu84

    khu84 Active Member

    Messages:
    441
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Run two queries side by side. I mean just run two quries 2nd one immediately after first.

    Or if you are trying to maintain a mirror database or table you can have a script that is run by cron job lets say every hour to copy the data of one table to another table or may be same table in another database. Here is one such script with whole explanation: http://codingtricks.blogspot.com/2008/02/copy-all-tables-of-one-mysql-db-to.html
     
    khu84, Jan 13, 2009 IP