The forgot password function you are trying to implement isn't really viable.
Anyone could go on to your website, enter someone elses username and then reset that persons password.
The best method is to firstly, allow a person to enter their username.
Send an e-amil to their e-mail address with a password reset link.
The link will go to your website, and you will then send out a new password for them to log in with.
The benefits of the above is that, if I went to your website and entered a username, the password wouldn't change, unless the user associated with that username clicked on the link sent to them.