Maybe run a select query, checking the database for the username and email they entered. Create an if else statement checking the return value of the query. If it returns FALSE, the username is ok to use, so carry on with the insert. If it returns a result set, you know that either the username or email address has already been registered, because it was matched in your table, so send them back to the form where you print an error?
Not sure if this is a good way but this is how I checked before when I was trying the user login system. It worked ok for me. There are bound to be plenty of better ways though I'm sure.