I am trying to insert incoming form values into my PostgreSQL database table on Heroku. This is the Go function being used:
func Insert(w http.ResponseWriter, r *http.Request) {
db := dbConn()
if r.Method == "POST" {
nameo := r.FormValue("name")
typeo := r.FormValue("asslia")
balanceo := r.FormValue("balance")
insForm, err := db.Prepare("INSERT INTO al(name, asslia, balance) VALUES( ? , ? , ? )")
if err != nil {
panic(err.Error())
}
insForm.Exec(nameo, typeo, balanceo)
log.Println("INSERT: Name: " + nameo + " | Type: " + typeo)
}
defer db.Close()
http.Redirect(w, r, "/", 301)
}
I keep getting the error pq: syntax error at or near ","
at the line insForm, err := db.Prepare("INSERT INTO al(name, asslia, balance) VALUES( ? , ? , ? )")
The table was previously created as such:
CREATE TYPE types AS ENUM ('asset', 'liability');
CREATE TABLE IF NOT EXISTS al
(id SERIAL,
asslia TYPES,
balance MONEY,
name VARCHAR(64) NOT NULL UNIQUE,
CHECK (CHAR_LENGTH(TRIM(name)) > 0));
What am I doing wrong?