Do this on your else statement:
else {
echo mysql_insert_id();
}
Though I do not recommend it because MySQL extension is deprecated in newer versions of PHP. Generally to issue queries to MySQL programmers use the MySQLi or the PDO extension of PHP. Try doing it using MySQLi if you can. It's equivalent is the mysqli_insert_id() function.