@boriskeba: when you post code on the forums, you need to format it so it will display correctly. (I’ve edited your post above for you.)
You can highlight your code, then use the </> button in the editor window, or you can place three backticks ``` (top left key on US/UK keyboards) on a line above your code, and three on a line below your code. I find this approach easier, but unfortunately some European and other keyboards don’t have that character.
since the validation code is not depending on the password, no.
Note, you should add a UNIQUE constraint on the email and username field in your DB. This way it’s impossible to have duplicate values (otherwise you have a time window of smth. around 100 ms where it’s possible to create duplicates).
Also note that you should never ever modify the user password! And $password = md5($password); is a very error prone line since you can’t tell in your code if you are using the plain-text or hashed password.