PHP tem uma função chamada: mysql_insert_id(); mais informaçõeshttps://lt.php.net/manual /en/function.mysql-insert-id.php