use mysql_insert_id(); to grap the last insert id. Take a look for more information mysql_insert_id()
Warning: mysql_* is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: