There are a lot of problems with what you're doing here.
First, you are vulnerable to SQL injections because you are not sanitizing your inputs in the SQL.
Second, you should avoid using a fast hash like SHA512 for this. It's not considered secure anymore. Take a look at this question. You basically want to use an adaptive hash function like bcrypt.