Your question is not that clear, so let me phrase what I think is going on, and correct me where I have misinterpret you.
You have a table that stores information about photos. The table has an ID column with auto_increment set. Whenever you insert something into the database, you want to retreive this ID so you can create a folder to store your photos in. Correct?
Basically, execute your query, which would be something like:
INSERT INTO `myTable` SET `name`="Name of photo", `filename`="photo.png"
then do the following:
$last_id = mysql_insert_id();
or if you are using mysqli:
$last_id = mysqli_insert_id();
With this $last_id
you can now make a folder etc...