Proper way to query to check if credentials already exist

665 views Asked by At

I currently have:

func foo (w http.ResponseWriter, req *http.Request) {
    chekr := `SELECT FROM public."Users" WHERE email=$1`
    err = db.QueryRow(chekr, usr.Email).Scan()
    if err != sql.ErrNoRows {
        data, err := json.Marshal("There is already a user with this email")
        if err != nil { w.Write(data) }
    }
    // code that should run if email isn't found
}

However, I find it never working and always passing the if block.

1

There are 1 answers

3
Nathan Takemori On

As the above comment stated, I forgot the */1. QueryRow works, I just had another error somewhere. As others have stated there's others errors, this is just for one case to test.