0

我需要添加什么代码,以便如果密码!=密码2然后中止注册,我不确定该怎么做,你能帮我吗?

    httpclient=new DefaultHttpClient();
    httppost= new HttpPost("http://purelymean.com/ANDROID/adduser.php"); // make sure the url is correct.
    //add your data
    nameValuePairs = new ArrayList<NameValuePair>(4);
    // Always use the same variable name for posting i.e the android side variable name and php side variable name should be similar, 
    nameValuePairs.add(new BasicNameValuePair("username",usern.getText().toString().trim()));  // $Edittext_value = $_POST['Edittext_value'];
    nameValuePairs.add(new BasicNameValuePair("password",password.getText().toString().trim())); 
    nameValuePairs.add(new BasicNameValuePair("password2",password2.getText().toString().trim())); 
    nameValuePairs.add(new BasicNameValuePair("email",email.getText().toString().trim())); 

    if (password != password2) {
        Toast.makeText(Register.this,"Passwords Dont Match",Toast.LENGTH_SHORT).show();

    }

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    //Execute HTTP Post Request
    response=httpclient.execute(httppost);
    // edited by James from coderzheaven.. from here....
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    final String response = httpclient.execute(httppost, responseHandler);
    System.out.println("Response : " + response); 
    runOnUiThread(new Runnable() {
        public void run() {
            tv.setText("Response from PHP : " + response);
            dialog.dismiss();
        }
    });
4

1 回答 1

0

不要使用密码 != 密码 2 来比较字符串。要比较字符串,我们使用 String1.equals(String2)。如果此条件为假,则 Toast 密码不匹配并取消注册。

if (!(password.equals(password2))) {
   Toast.makeText(Register.this,"Passwords Dont Match",Toast.LENGTH_SHORT).show();
}
于 2013-04-20T03:50:56.600 回答