我是 android 新手,如何将值从 android 插入到 php mysql 我尝试了以下代码,它没有显示任何错误但无法正常工作。谁能帮我。谁能纠正我的错误。
public class MainActivity extends Activity{
EditText username, email, password;
Button btn;
HttpResponse response;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
username = (EditText) findViewById(R.id.usr_name);
email = (EditText) findViewById(R.id.email);
password = (EditText) findViewById(R.id.password);
btn = (Button) findViewById(R.id.regbtn);
btn.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/androidtest.php");
try{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("uname", username.toString()));
nameValuePairs.add(new BasicNameValuePair("email", email.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("password", password.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
}catch(Exception e){
e.printStackTrace();
}
}
});
}
}