We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
func (m *SnippetModel) Insert(title string, content string, expires int) (int, error) { var pk int err := m.DB.QueryRow(`INSERT INTO snippets VALUES($1,$2,$3) RETURNING id`, title, content, expires).Scan(&pk) if err != nil { return 0, err } return pk, nil }
i want to return last index has been inserted into db
func (app *Application) snippetCreate(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.Header().Set("Allow", "Post") app.ClientError(w, http.StatusMethodNotAllowed) return } title := "O snail" content := "O snail\nClimb Mount Fuji,\nBut slowly, slowly!\n\n– Kobayashi Issa" expires := 7 id, err := app.snippets.Insert(title, content, expires) if err != nil { app.ServeError(w, err) return } // Redirect the user to the relevant page for the snippet. http.Redirect(w, r, fmt.Sprintf("/snippet/view?id=%d", id), http.StatusSeeOther) }
but it always gives me that error
The text was updated successfully, but these errors were encountered:
Your INSERT query needs columns. Try updating 2nd line in Insert func to:
Insert
err := m.DB.QueryRow(`INSERT INTO snippets (title, content, expires) VALUES ($1,$2,$3) RETURNING id`, title, content, expires).Scan(&pk)
Sorry, something went wrong.
thanks for your response ,i finally solved that dummy error
No branches or pull requests
i want to return last index has been inserted into db
but it always gives me that error
The text was updated successfully, but these errors were encountered: