If you're using mySQL the use the function mysql_insert_id()
It will return the most recent auto increment entered into the DB.
Use like so:
echo(mysql_insert_id());
If your autoincrement is a BIGINT then use the mySQL function LAST_INSERT_ID(); instead
Use like so:
$query = "SELECT LAST_INSERT_ID()";
yada yada.....