Design problem with auto-increment fields
So you just need to fetch the last auto-increment value that was inserted? There are a couple of ways to do this, but they're all pretty simple.

Query: SELECT LAST_INSERT_ID()

php mysql: $id = mysql_insert_id($mysql_conn);
http://php.net/manual/en/function.mysql-insert-id.php

php mysqli: $id = $mysqli-&gt;insert_id;
http://php.net/manual/en/mysqli.insert-id.php

Both of those links have some example code that looks pretty easy to follow.