/    Sign up×
Community /Pin to ProfileBookmark

Return value from INSERT into innerHTML?

This is the query that is executed. Which work as query
https://www.db-fiddle.com/f/eaQG8H4yqY9hnQBZjzJgz/65

But how do I get this id into innerHTML?
My attempt shows “null”
https://jsfiddle.net/k7od12fa/3/

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@sibertauthorJan 12.2022 — ["Return value from INSERT?","Return value from INSERT into innerHTML?"]
Copy linkTweet thisAlerts:
@sibertauthorJan 14.2022 — I found a solution. The AJAX and the SQL query was correct, but no value submitted. So I changed the Go API to from execute to a normal "fetch row". Not obvious, but it worked. For those who are using Golang, here is the API code for returning the id (FWIW):

``<i>
</i>// simplified endpoint
func Create(w http.ResponseWriter, r *http.Request) {
data = new(query, val)
json.NewEncoder(w).Encode(data)
}

// add new record
func new(query string, val string) interface{} {
var id int
err := db.QueryRowx(query, val).Scan(&amp;id)
if err != nil {
return nil
}
return (id)
}<i>
</i>
``
×

Success!

Help @sibert spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...