insert into sorgusundan sonra mysql_insert_id() ile oluyordu sanırım

http://php.net/manual/en/function.mysql-insert-id.php