java - Error posting data with android -
java - Error posting data with android -
i having error can't seem figure out why. trying post info php file , falling grab error. toast getting in grab "data not sent", getting "data prepared" toast right before it. take , help me identify problem is?
the android method:
public void inserttodb(string data){ seek { httpclient client=new defaulthttpclient(); httppost getmethod=new httppost("http://shawnc.webuda.com/upload.php"); arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); namevaluepairs.add(new basicnamevaluepair("rpm",data)); getmethod.setentity(new urlencodedformentity(namevaluepairs, http.utf_8)); string toasttext = "data prepared"; toast.maketext(getapplicationcontext(), toasttext, toast.length_short).show(); seek { client.execute(getmethod); toasttext = "data has been sent: " + data; toast.maketext(getapplicationcontext(), toasttext, toast.length_short).show(); }catch(exception e){ toasttext = "data not sent"; toast.maketext(getapplicationcontext(), toasttext, toast.length_short).show(); } }catch(exception e){ string toasttext = "data not prepared"; toast.maketext(getapplicationcontext(), toasttext, toast.length_short).show(); } }
and php file:
<? $hostname_host ="mysqlxxxxx.smarterasp.net"; $database_host ="db_xxxxx_db"; $username_host ="9xxxxx_db"; $password_host ="password"; $server= mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),e_user_error); mysql_select_db("db_xxxxx_db"); $sql=mysql_query("insert driverdata (rpm)values('".$_request['rpm']."')"); $r=mysql_query($sql); if(!$r) echo "error in query: ".mysql_error(); mysql_close(); ?>
when not know problem seek replace php script by
<?php echo "ok"; ?>
and seek read response php
try { httpresponse response = client.execute(getmethod); toasttext = "data has been sent: " + data;
when response ok problem in php.
when utilize httppost utilize code response. when have response http request ok.
httpclient client = new defaulthttpclient(httpparameters); client.getparams().setparameter("http.protocol.version", httpversion.http_1_1); client.getparams().setparameter("http.socket.timeout", 2000); client.getparams().setparameter("http.protocol.content-charset", http.utf_8); httpparameters.setbooleanparameter("http.protocol.expect-continue", false); httppost request = new httppost("http://xxxxxx.com/upload.php"); request.getparams().setparameter("http.socket.timeout", 5000); list<namevaluepair> postparameters = new arraylist<namevaluepair>(); postparameters.add(new basicnamevaluepair("rpm",data)); seek { urlencodedformentity formentity = new urlencodedformentity(postparameters, http.utf_8); request.setentity(formentity); httpresponse response = client.execute(request); //do response
java php android sql post
Comments
Post a Comment