将用户插入数据库ANDROID APP

时间:2014-11-23 21:14:37

标签: java android

我试图将用户登录名和密码插入mysql数据库

到目前为止我所拥有的是:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signup);
}

public void validateUser(View v) {
    final EditText username = (EditText) findViewById(R.id.username);
    final EditText password = (EditText) findViewById(R.id.password);
    final String login_name = username.getText().toString();
    final String password_name = password.getText().toString();
    new Thread(new Runnable() {
        public void run() {
            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://website-name/insert.php");
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("username", login_name));
                nameValuePairs.add(new BasicNameValuePair("password", password_name));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
            } 
            catch (ClientProtocolException e) {
            } catch (IOException e) {
            }
        }
        }).start();

    Intent homepageIntent = new Intent(signup.this, homepage.class);
    startActivity(homepageIntent);
    }
}

在我的xml文件中,单击按钮时执行validateUser。但是,当我运行模拟器并创建用户帐户时,我的程序会将我引导至主页,但不会将用户添加到数据库。世界上我做错了什么?

1 个答案:

答案 0 :(得分:0)

尝试回复http://website-name/insert.php并尝试从那里解决问题...或尝试将您要发送的内容写入文件。如果您可以回显您在服务器端发送的内容或写入文件,那么就是问题所在。

但是不要从客户端登录到DB。