php - Can't insert into mysql when updating gps location from android -
php - Can't insert into mysql when updating gps location from android -
a simple android application. application can coordinate of user location , sending lat , long mysql. android code :
 public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);   btnshowlocation = (button) findviewbyid(r.id.btnshowlocation);   button insert=(button) findviewbyid(r.id.btnshowlocation);     insert.setonclicklistener(new view.onclicklistener() {          @override         public void onclick(view v) {              gps = new gpstracker(androidgpstrackingactivity.this);              // todo auto-generated method stub             if(gps.cangetlocation()){                 lat = (float) gps.getlatitude();              lng = (float) gps.getlongitude();              lat2= float.tostring(lat);              lng2= float.tostring(lng);                insert();              toast.maketext(getapplicationcontext(), "success insert - \nlat: " + lat2 + "\nlong: " + lng2, toast.length_long).show();            }else{             // can't location             // gps or network not enabled             //  inquire user enable gps/network in settings             gps.showsettingsalert();         }         }     }); }  public void insert() {     arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();      namevaluepairs.add(new basicnamevaluepair("lat2", lat2));     namevaluepairs.add(new basicnamevaluepair("lng2", lng2));       seek {         httpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://192.168.56.1/rute2/insert_android.php");         httppost.setentity(new urlencodedformentity(namevaluepairs));         httpresponse response = httpclient.execute(httppost);         httpentity entity = response.getentity();         = entity.getcontent();         log.e("pass 1", "connection success ");     }  grab (exception e) {         log.e("fail 1", e.tostring());         toast.maketext(getapplicationcontext(), "invalid ip address",                 toast.length_long).show();     }       seek {         bufferedreader reader = new bufferedreader(new inputstreamreader(                 is, "iso-8859-1"), 8);         stringbuilder sb = new stringbuilder();         while ((line = reader.readline()) != null) {             sb.append(line + "\n");         }         is.close();         result = sb.tostring();         log.e("pass 2", "connection success ");     }  grab (exception e) {         log.e("fail 2", e.tostring());     }       seek {         jsonobject json_data = new jsonobject(result);         code = (json_data.getint("code"));          if (code == 1) {             toast.maketext(getbasecontext(), "inserted successfully",                     toast.length_short).show();         } else {             toast.maketext(getbasecontext(), "sorry,  seek again",                     toast.length_long).show();         }     }  grab (exception e) {         log.e("fail 3", e.tostring());     } }    and table marker_awal
this php file
<?php $host='localhost'; $uname='root'; $pwd=''; $db="test";  $con = mysql_connect($host,$uname,$pwd) or die("connection failed"); mysql_select_db($db,$con) or die("db selection failed");  $lat2=(isset($_request['lat2']) ? $_request['lat2'] : ''); $lng2=(isset($_request['lng2']) ? $_request['lng2'] : '');   //$lat2=$_request['lat']; //$lng2=$_request['lng'];  var_dump($lat2);    $flag['code']=0;  if($r=mysql_query("insert markers_awal values('','$lat2','$lng2','') ",$con)) {     $flag['code']=1;     echo"hi"; }  print(json_encode($flag)); mysql_close($con); ?>    i got no error in application can`t insert database.
 php android mysql gps 
 
Comments
Post a Comment