Add works

This commit is contained in:
Dan Ballard 2015-07-08 20:30:47 -07:00
parent 35406174a2
commit 2fa54d6954
2 changed files with 9 additions and 6 deletions

View File

@ -51,9 +51,9 @@ func LoadCategories(db *sql.DB) {
func Add(db *sql.DB, name string, parent int) error {
var err error
if parent < 0 {
err := db.Exec("INSERT INTO categories (name) VALUE ($1)", name)
_, err = db.Exec("INSERT INTO categories (name) VALUES ($1)", name)
} else {
err := db.Exec("INSERT INTO categories (name, parent_id) VALUE ($1, $2)", name, parent)
_, err = db.Exec("INSERT INTO categories (name, parent_id) VALUES ($1, $2)", name, parent)
}
if err != nil {
fmt.Println("Categories DB Error Add(): " , err)

View File

@ -293,13 +293,16 @@ func categoryChangeParentHandler(w http.ResponseWriter, r *http.Request, user *u
func categoryAddHandler(w http.ResponseWriter, r *http.Request, user *user.User) {
session, _ := store.Get(r, "c_user")
name := categoryFromReqArg(r.FormValue("name"))
parent := categoryFromReqArg(r.FormValue("parent"))
name := r.FormValue("name")
parent, perr := strconv.Atoi(r.FormValue("parent"))
if name == nil {
if perr != nil {
parent = -1
}
if name == "" {
session.AddFlash("Invalid category name", flash_err)
} else {
err := category.Add(db, name, parent)
err := categories.Add(db, name, parent)
if err != nil {
session.AddFlash("Error commiting to Database", flash_err)
} else {