Skip to content
Advertisement

“sql: no rows in result set”

I am handling user auth data posted to my Go backend through an HTML form. I am building on some boilerplate to learn Go better.

My problem is what the following func returns:

The first if statement validates the input, and that works fine (error if the email isn’t in proper email format, no error if it is). However, if input is properly validated, the else clause of the second statement is triggered, and the following JSON is returned:

It is probably useful to also post the relevant code in my User model:

How do I resolve the sql: no rows in result set error?

Advertisement

Answer

You should change the order of operations in your code. At first you need to get data from request with if err := c.ShouldBindWith(&signinForm, binding.Form); err != nil { and after that you need to try get data from database with user, err := userModel.Signin(signinForm)

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement