Very simple example:
Your table : users
Your fields : users_id, user_name, zip_code, created
Unique Index : user_name
INSERT INTO users (user_name, zip_code, created)
VALUES
('joe',75034,'2009-06-11')
ON DUPLICATE KEY UPDATE users_id=LAST_INSERT_ID(id)
The user_name has a unique index; so, you can't add it more than once. When you use the SQL above, it will add just fine the first time. The second time, it won't actually do the insert. The way the on duplicate key is setup, you can now fetch the last insert id from mysql with PHP and know what the users_id was whether it was a true insert or a duplicate.