Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
468 B
1
Indexable
Never
func saveHandler(w http.ResponseWriter, r *http.Request) {
	db, err := sql.Open("mysql", "root:@tcp(localhost:3306)/test")
	if err != nil {
		log.Fatal(err)
	}
	defer db.Close()

	if err := r.ParseForm(); err != nil {
		log.Fatal(err)
	}

	text := r.FormValue("text")
	text2 := r.FormValue("text2")

	_, err = db.Exec("INSERT INTO users (username, password) VALUES (?, ?)", text, text2)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Fprint(w, "Data saved successfully")
}