android - Register with MySQL database and PHP -


i want build app users can regist username , password , data send mysql database using php php code

$connect = mysqli_connect("mysql1.000webhost.com","a5900443_jekn","123456","a5900443_jek");  if(mysqli_connect_errno($connect)) {     echo "failed connect mysql: " . mysqli_connect_error(); } else {     echo "success"; }  $username = isset($_post['username']) ? $_post['username'] : ''; $password = isset($_post['password']) ? $_post['password'] : '';  $query = mysqli_query($connect, "insert users (username, password) values ('$username' ,'$password') ");  mysqli_close($connect); ?> 

i try different android project data doesn't save in database can give me how send username , password android app php code?

this android java:

public class mainactivity extends activity{  strictmode.threadpolicy policy = new           strictmode.threadpolicy.builder().permitall().build();  private edittext username;  private edittext password;    public void oncreate(bundle savedinstancestate)  {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main);      username = (edittext) findviewbyid(r.id.e1);     password = (edittext) findviewbyid(r.id.e2);      button button = (button) findviewbyid(r.id.button1);     button.setonclicklistener(new view.onclicklistener()         {             public void onclick(view view)             {                  string result = null;                 inputstream = null;                     arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();                  namevaluepairs.add(new basicnamevaluepair("username",username.gettext().tostring                                                           ()));                  namevaluepairs.add(new basicnamevaluepair("password",password.gettext().tostring                                                           ()));                  strictmode.setthreadpolicy(policy);                    //http post                 try{                     httpclient httpclient = new defaulthttpclient();                     httppost httppost = new httppost("http://fkrucusowtcl.web44.net/register.php");                     httppost.setentity(new urlencodedformentity(namevaluepairs));                     httpresponse response = httpclient.execute(httppost);                      httpentity entity = response.getentity();                     = entity.getcontent();                      log.e("log_tag", "connection success ");                     toast.maketext(getapplicationcontext(), "pass", toast.length_short).show();                 }                   catch(exception e)                 {                     log.e("log_tag", "error in http connection "+e.tostring());                     toast.maketext(getapplicationcontext(), "connection fail", toast.length_short).show();                  }                 //convert response string                 try{                     bufferedreader reader = new bufferedreader(new inputstreamreader(is,"iso-8859-1"),8);                     stringbuilder sb = new stringbuilder();                     string line = null;                     while ((line = reader.readline()) != null)                      {                      }                     is.close();                      result=sb.tostring();                 }                 catch(exception e)                 {                     log.e("log_tag", "error converting result "+e.tostring());                 }                   try{                      jsonobject json_data = new jsonobject(result);                      charsequence w= (charsequence) json_data.get("re");                      toast.maketext(getapplicationcontext(), w, toast.length_short).show();                   }                 catch(jsonexception e)                 {                     log.e("log_tag", "error parsing data "+e.tostring());                     toast.maketext(getapplicationcontext(), "jsonarray fail", toast.length_short).show();                 }                }         });    } 

where wrong doesn't send data php

take @ http://www.androidhive.info/2014/01/how-to-create-rest-api-for-android-app-using-php-slim-and-mysql-day-12-2/

this guide on how create rest api, allow register , other functions database securely.


Comments