in reply to code help

Supposing this is a multi-user database, you'll have a race condition if you use the select statement to pick an unused email addr.

Create a Used-Names table where EMAIL name is a unique index or constraint. Insert into the table in a loop where you are eval()ing $sth->execute() and checking DBI::err or DBI::errstr for your database vendor specific "duplicate key/unique field" error.