This question already has an answer here:
Need a help. I want to get last inserted id from database in insert query from MSSQL database using PHP as a Programming language.
</div>
You have mysql_insert_id, mysqli_insert_id and $mysqli->insert_id for mysql, mysqli procedural and mysqli object style. All depends on mysql extension you are using
Try using PDO, there is a method called lastInsertId for that. If you change your database, your PHP code will be the same, the only change will be the PDO driver.
Read more: http://www.php.net/manual/en/pdo.lastinsertid.php