mysql - how to insert data into database using play framework and scala -


hi using play framework , scala. insert userprofile data database not working. sign in , signup functions working , database insertion , connection correct.. in console mysql connection created visible no problem mysql connection

    method  inside application       def saveuserprofile = action { implicit request =>                 if (request.session.get("userid") == none) {                   results.redirect("/")                 } else {                     val user_account_id = request.session.get("userid").get.tolong                   val useraccount = useraccount.findbyuseraccountid(user_account_id).get                    userprofileform.bindfromrequest.fold(                      errors => badrequest(views.html.userprofile(errors, useraccount)),       real problem starts here... when debug program  next line not executed..                     userprofile => {                        val userprofileopt = useraccount.userprofile(11)                       println(userprofileopt)                      in here userprofileopt contain null value.. real problem..                     userprofileopt=null not contain id..                         userprofileopt match {                           case none =>                            val updateduserprofile = userprofile(notassigned,                               option(user_account_id),                              userprofile.name,                             userprofile.date_of_birth, userprofile.gender,                              userprofile.image,userprofile.status)                              userprofile.insert(updateduserprofile)                           val alert: alert = new alert("success", " user profile saved")                           common.setalert(alert)                           case some(userprofilefound: userprofile) =>                            val updateduserprofile = userprofile(userprofilefound.id,                             userprofilefound.user_account_id, userprofilefound.name,                             userprofilefound.date_of_birth, userprofilefound.gender,                             userprofilefound.image,userprofilefound.status)                              userprofile.update(updateduserprofile)                           val alert: alert = new alert("success", " user profile updated")                           common.setalert(alert)                       }                       results.redirect("/userprofile")                     })                 }               }    , userprofile form method inside application ,    /**    * userprofile form    */   val userprofileform = form(     forms.mapping(       "id" -> ignored(notassigned: pk[long]),       "user_account_id" ->optional(longnumber),       "name" -> nonemptytext,       "data of birth" -> date,       "gender" -> nonemptytext,       "image" -> nonemptytext,       "status" -> nonemptytext )(userprofile.apply)(userprofile.unapply))    def index = action {     val alert: alert = new alert("", "")     common.setalert(alert)     ok(views.html.index(signinform, "friends+"))       }   ....and method under.. method inside model , model name userprofile.....   def userprofile(user_account_id:long)={     db.withconnection{ implicit connection =>     val userdetail = sql(     """         select * user_profile         user_account_id = {user_account_id}     """).on(         'user_account_id -> user_account_id).as(userprofile.simple.singleopt)           userdetail     }   }     ....i strugle   problem       days ...        don't know how handle problem.. 

i have same issue , solve by:

           val userprofileform = form(             forms.mapping(               "id" -> ignored(notassigned: pk[long]),               "user_account_id" -> optional(longnumber),               "name" -> nonemptytext, 

the problem here type of date of birth date , format here:

              "date_of_birth" -> date("yyyy/mm/dd"),               "gender" -> nonemptytext,               "image" -> nonemptytext,               "status" -> nonemptytext)                       (userprofile.apply)(userprofile.unapply))                        println("1") 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -