Validating the Form with MySQL

Can anyone help me regarding the issue of MySQL form validator that I want to apply to my web page?
How can I validate the form in case if the username in the database already exists when a new user wants to create the account?
I need the expert opinion.
