This mainly depends on the interface you use to access MySQL.
If you use PDO (recommended), you should use PDO::lastInsertId() : http://us.php.net/manual/en/pdo.lastinsertid.php
If you are using MySQL, you must use mysql_insert_id() http://php.net/manual/en/function.mysql-insert-id.php
If you are using MySQLi, you should use mysqli_insert_id() : http://us.php.net/manual/en/mysqli.insert-id.php
Just call whichever function is right right after the completion of INSERT.
It is important to note that you probably do not want to retrieve the id from the database using SELECT, because if you have several authors, you can get the identifier that some other thread inserted. In the best case, you will work with incorrect data, and in the worst case, you may have serious security problems and / or corruption.
Don MacAskill
source share