I am developing a small application and for that authentication is needed. That I’m trying to develop by connecting to MYsql db through php.
add uname/pw –> loging –> send to php –> check db –> ok sends back to android –> authenticated. / error sends back to re loging.
I have developed so far, I think this is how it should be but I’m NOT sure since I’m really new to the cording.
Please be kind enough to help me with cording. Thank you.
public class Loging extends Activity{
TextView txt;
EditText uname,pwd;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.loging);
Button b = (Button)findViewById(R.id.log);
uname = (EditText)findViewById(R.id.uname);
pwd = (EditText)findViewById(R.id.pwd);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("name", uname.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("Pass", pwd.getText().toString()));
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.helloworld.com/report.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
}
catch(Exception e)
{
Log.e("log_tag","Error in http connection"+e.toString());
}
}
});
}
}
1 Answer