php - make httppost in android properly -


i'm trying make android app communicates php file/database.
don't working, i'm new @ kind of android programming.
got tutorial:

new dialoginterface.onclicklistener() {  public void onclick(dialoginterface dialog,int id) {  name = userinput.gettext().tostring();  httpclient httpclient = new defaulthttpclient();  httppost httppost = new httppost("http://www.test.com/register.php");  try {       list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(1);       namevaluepairs.add(new basicnamevaluepair("name", name));       httppost.setentity(new urlencodedformentity(namevaluepairs));       httpresponse response = httpclient.execute(httppost);    } catch (clientprotocolexception e) {     // todo auto-generated catch block   } catch (ioexception e) {     // todo auto-generated catch block   }   } 

php code:

// including database connection $name= $_post['name'];  $register= "insert users (name, level) values(".$name.", 1)";  $result   = $conn->prepare($register); $result->execute(); 

when startup app instantly crashes.
i'm doing wrong?
code still work?
did forgot something?

all database communication should done in background. can done using asynctask or other worker. need internet permission, add line manifest :

<uses-permission android:name="android.permission.internet"/> 

but i'd recommend use library retrofit api calls. spares pain in ass, , combination of gson powerfull.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -