What you need to do is to get the last id directly after your query. Like this:
$intLastId = mysql_insert_id();
Then you can use it later in an UPDATE query for example (or whatever you need it for) like this:
UPDATE table SET name = \"john\" WHERE id = $intLastId
Remeber that your previous query must generate an auto_increment value. If you don\'t have an auto_increment field, then mysql_insert_id() will return 0.