java - How to Update Data using PHP MYSQL in Android -
i writing app in need update data using php mysql, , every time getting message "update data successfully". whenever see database, not getting changes in values.
logcat says:
09-04 12:00:50.176: d/gralloc_goldfish(538): emulator without gpu emulation detected. 09-04 12:08:38.646: d/inputeventconsistencyverifier(538): keyevent: action_up key not down. 09-04 12:08:38.646: d/inputeventconsistencyverifier(538): in com.android.internal.view.menu.expandedmenuview@4136ec30 09-04 12:08:38.646: d/inputeventconsistencyverifier(538): 0: sent @ 552986000000, keyevent { action=action_up, keycode=keycode_menu, scancode=229, metastate=0, flags=0x8, repeatcount=0, eventtime=552986, downtime=552899, deviceid=0, source=0x101 } 09-04 12:08:39.885: d/(538): userloginappointmentactivity txtphone[before] :: android.widget.edittext@41389238 09-04 12:08:39.885: d/(538): userloginappointmentactivity txtpass[before] :: android.widget.edittext@4138acb0 09-04 12:08:40.205: w/textlayoutcache(538): computevalueswithharfbuzz -- need force single run 09-04 12:08:42.976: d/dalvikvm(538): gc_concurrent freed 131k, 3% free 10157k/10375k, paused 6ms+4ms 09-04 12:08:46.357: d/inputeventconsistencyverifier(538): keyevent: action_up key not down. 09-04 12:08:46.357: d/inputeventconsistencyverifier(538): in android.widget.edittext@4138acb0 09-04 12:08:46.357: d/inputeventconsistencyverifier(538): 0: sent @ 561313000000, keyevent { action=action_up, keycode=keycode_tab, scancode=15, metastate=0, flags=0x8, repeatcount=0, eventtime=561313, downtime=561190, deviceid=0, source=0x101 } 09-04 12:08:49.746: d/(538): userloginappointmentactivity txtphone :: android.widget.edittext@41389238 09-04 12:08:49.746: d/(538): userloginappointmentactivity txtpass :: android.widget.edittext@4138acb0 09-04 12:08:50.066: d/(538): userloginappointmentactivity resultserver :: {"statusid":"1","userid":"24","error":"login ok"} 09-04 12:08:50.066: d/(538): userloginappointmentactivity strstatusid[before] :: 0 09-04 12:08:50.066: d/(538): userloginappointmentactivity struserid[before] :: 0 09-04 12:08:50.066: d/(538): userloginappointmentactivity strerror[before] :: unknow status! 09-04 12:08:50.066: d/(538): userloginappointmentactivity strstatusid[after] :: 1 09-04 12:08:50.076: d/(538): userloginappointmentactivity struserid[after] :: 24 09-04 12:08:50.076: d/(538): userloginappointmentactivity strerror[after] :: login ok 09-04 12:08:50.105: d/(538): userloginappointmentactivity userid intent :: 24 09-04 12:08:51.496: d/dalvikvm(538): gc_concurrent freed 204k, 4% free 10345k/10695k, paused 5ms+5ms 09-04 12:08:55.475: d/(538): sappointmentid :: 24 09-04 12:08:55.475: d/(538): sappointmentid :: 53 09-04 12:08:56.166: d/(538): resultserver - getbymemberidr:: {"userid":"24","appointmentid":"53","type":"cardiology","date":"12-09-2013","time":"22:15","status":"pending"} 09-04 12:08:56.166: d/(538): struserid :: 24 09-04 12:08:56.176: d/(538): strappointmentid :: 53 09-04 12:08:56.176: d/(538): strtype :: cardiology 09-04 12:08:56.176: d/(538): strdate :: 12-09-2013 09-04 12:08:56.176: d/(538): strtime :: 22:15 09-04 12:11:06.866: d/dalvikvm(538): gc_concurrent freed 278k, 4% free 10459k/10887k, paused 7ms+7ms 09-04 12:15:36.425: d/(538): resultserver - updatedata:: {"statusid":"1","message":"updated"} 09-04 12:15:37.015: d/dalvikvm(538): gc_concurrent freed 330k, 5% free 10572k/11015k, paused 7ms+9ms
php script:
<?php $objconnect = mysql_connect("localhost","root",""); $objdb = mysql_select_db("android"); $struserid = $_post["suserid"]; $strappointmentid = $_post["sappointmentid"]; $strtype = $_post["stype"]; $strdate = $_post["sdate"]; $strtime = $_post["stime"]; /*** update ***/ $strsql = " update book_appointment set type = '".$strtype."', date = '".$strdate."', time = '".$strtime."' appointmentid = '".$strappointmentid."' "; $objquery = mysql_query($strsql); if(!$objquery) { $arr['statusid'] = "0"; $arr['message'] = "cannot save data!"; } else { $arr['statusid'] = "1"; $arr['message'] = "updated"; } mysql_close($objconnect); echo json_encode($arr); ?>
updateactivity.java:-
public class updateactivity extends activity { private static final string tag = null; @suppresslint("newapi") @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_update); // permission strictmode if (android.os.build.version.sdk_int > 9) { strictmode.threadpolicy policy = new strictmode.threadpolicy.builder().permitall().build(); strictmode.setthreadpolicy(policy); } showinfo(); // btnsave button btnsave = (button) findviewbyid(r.id.btnsave); // perform action on click btnsave.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { if(savedata()) { // when save complete intent newactivity = new intent(updateactivity.this,rescheduleactivity.class); startactivity(newactivity); } } }); // btncancel final button btncancel = (button) findviewbyid(r.id.btncancel); // perform action on click btncancel.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { intent newactivity = new intent(updateactivity.this,rescheduleactivity.class); startactivity(newactivity); } }); } public void showinfo() { // txtmemberid,txtusername,txtpassword,txtconpassword,txtname,txtemail,txttel final textview tuserid = (textview)findviewbyid(r.id.txtuserid); final textview tappointmentid = (textview)findviewbyid(r.id.txtappointmentid); final textview ttype = (textview)findviewbyid(r.id.txttype); final textview tdate = (textview)findviewbyid(r.id.txtdate); final textview ttime = (textview)findviewbyid(r.id.txttime); button btnsave = (button) findviewbyid(r.id.btnsave); button btncancel = (button) findviewbyid(r.id.btncancel); string url = "http://10.0.2.2/appointments/getbymemberidr.php"; intent intent= getintent(); final string userid = intent.getstringextra("userid"); final string appointmentid = intent.getstringextra("appointmentid"); list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("suserid", userid)); params.add(new basicnamevaluepair("sappointmentid", appointmentid)); string resultserver = gethttppost(url,params); log.d(tag, "resultserver - getbymemberidr:: " + resultserver); string struserid = ""; string strappointmentid = ""; string strtype = ""; string strdate = ""; string strtime = ""; jsonobject c; try { c = new jsonobject(resultserver); struserid = c.getstring("userid"); log.d(tag, "struserid :: " + struserid); strappointmentid = c.getstring("appointmentid"); log.d(tag, "strappointmentid :: " + strappointmentid); strtype = c.getstring("type"); log.d(tag, "strtype :: " + strtype); strdate = c.getstring("date"); log.d(tag, "strdate :: " + strdate); strtime = c.getstring("time"); log.d(tag, "strtime :: " + strtime); if(!struserid.equals("")) { tuserid.settext(struserid); tappointmentid.settext(strappointmentid); ttype.settext(strtype); tdate.settext(strdate); ttime.settext(strtime); } else { tuserid.settext("===="); tappointmentid.settext("===="); ttype.settext("===="); tdate.settext("===="); ttime.settext("===="); btnsave.setenabled(false); btncancel.requestfocus(); } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } } public boolean savedata() { // txtmemberid,txtpassword,txtname,txtemail,txttel final edittext txttype = (edittext)findviewbyid(r.id.txttype); final edittext txtdate = (edittext)findviewbyid(r.id.txtdate); final edittext txttime = (edittext)findviewbyid(r.id.txttime); //dialog final alertdialog.builder ad = new alertdialog.builder(this); ad.settitle("error! "); ad.seticon(android.r.drawable.btn_star_big_on); ad.setpositivebutton("close", null); string url = "http://10.0.2.2/appointments/updatedata.php"; list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("stype", txttype.gettext().tostring())); params.add(new basicnamevaluepair("sdate", txtdate.gettext().tostring())); params.add(new basicnamevaluepair("stime", txttime.gettext().tostring())); string resultserver = gethttppost(url,params); log.d(tag, "resultserver - updatedata:: " + resultserver); /*** default value ***/ string strstatusid = "0"; string strmessage = "unknow status!"; jsonobject c; try { c = new jsonobject(resultserver); strstatusid = c.getstring("statusid"); strmessage = c.getstring("message"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } // prepare save data if(strstatusid.equals("0")) { ad.setmessage(strmessage); ad.show(); return false; } else { toast.maketext(updateactivity.this, "update data successfully", toast.length_short).show(); } return true; } public string gethttppost(string url,list<namevaluepair> params) { stringbuilder str = new stringbuilder(); httpclient client = new defaulthttpclient(); httppost httppost = new httppost(url); try { httppost.setentity(new urlencodedformentity(params)); httpresponse response = client.execute(httppost); statusline statusline = response.getstatusline(); int statuscode = statusline.getstatuscode(); if (statuscode == 200) { // status ok httpentity entity = response.getentity(); inputstream content = entity.getcontent(); bufferedreader reader = new bufferedreader(new inputstreamreader(content)); string line; while ((line = reader.readline()) != null) { str.append(line); } } else { log.e("log", "failed download result.."); } } catch (clientprotocolexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } return str.tostring(); } }
i not sure think should need use below lines in savedata():
final textview tuserid = (textview)findviewbyid(r.id.txtuserid); final textview tappointmentid = (textview)findviewbyid(r.id.txtappointmentid);
so savadata() should this:
public boolean savedata() { final textview txtuserid = (textview)findviewbyid(r.id.txtuserid); final textview txtappointmentid = (textview)findviewbyid(r.id.txtappointmentid); final edittext txttype = (edittext)findviewbyid(r.id.txttype); final edittext txtdate = (edittext)findviewbyid(r.id.txtdate); final edittext txttime = (edittext)findviewbyid(r.id.txttime); //dialog final alertdialog.builder ad = new alertdialog.builder(this); ad.settitle("error! "); ad.seticon(android.r.drawable.btn_star_big_on); ad.setpositivebutton("close", null); string url = "http://10.0.2.2/appointments/updatedata.php"; list<namevaluepair> params = new arraylist<namevaluepair>(); params.add(new basicnamevaluepair("suserid", txtuserid.gettext().tostring())); params.add(new basicnamevaluepair("sappointmentid", txtappointmentid.gettext().tostring())); params.add(new basicnamevaluepair("stype", txttype.gettext().tostring())); params.add(new basicnamevaluepair("sdate", txtdate.gettext().tostring())); params.add(new basicnamevaluepair("stime", txttime.gettext().tostring())); string resultserver = gethttppost(url,params); log.d(tag, "resultserver - updatedata:: " + resultserver); /*** default value ***/ string strstatusid = "0"; string strmessage = "unknow status!"; jsonobject c; try { c = new jsonobject(resultserver); strstatusid = c.getstring("statusid"); strmessage = c.getstring("message"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } // prepare save data if(strstatusid.equals("0")) { ad.setmessage(strmessage); ad.show(); return false; } else { toast.maketext(updateactivity.this, "update data successfully", toast.length_short).show(); } return true; }
as know using userid , appointmentid fetch appointments, whenever doing changes requires particular userid , appointmentid point row, have clicked...may reason
please let me know :)
Comments
Post a Comment