第2步用
$id=mysql_insert_id();
就可以得到刚刚插入的id,然后再进行第三步操作

解决方案 »

  1.   

    谢谢.
    不会有紊乱的情况吧? 有没有可能一下插两个表的技术或者更好的表设计?
    http://cn.php.net/manual/zh/function.mysql-insert-id.php
      

  2.   

    这个应该是取得同一个连接下的上一次insert的id,所以应该不会有什么问题
      

  3.   

    谢谢. 在我给的那个URL里有一个user comment不错:
    frumler at the-beach dot no_spam dot net
    04-Aug-2001 11:17 
    If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this: INSERT INTO foo (auto,text) 
       VALUES(NULL,'text');              # generate ID by inserting NULL 
    INSERT INTO foo2 (id,text) 
       VALUES(LAST_INSERT_ID(),'text');  # use ID in second table ...found here: 
    http://www.mysql.com/doc/en/Getting_unique_ID.html 
    我决定用这种方法.