从php到android选择具有特定id的值

my codes is fine, not returning any errors but the values being retrieved are the same as the previous field..for example, if i set table3 to 'HELLO' then table4 is also 'HELLO' which is kinda wrong,i wanted separate values..here is my code...

my SigninActivity:

public class SigninActivity  extends AsyncTask<String,Void,String>{

 private TextView statusField,roleField, sampleField;
 private Context context;
 private int byGetOrPost = 0; 
 //flag 0 means get and 1 means post.(By default it is get.)
 public SigninActivity(Context context,TextView statusField,TextView roleField,TextView sampleField,int flag) {
  this.context = context;
  this.statusField = statusField;
  this.roleField = roleField;
  this.sampleField = sampleField;
  byGetOrPost = flag;
 }

 protected void onPreExecute(){

 }
  @Override
  protected String doInBackground(String... arg0) {
  if(byGetOrPost == 0){ //means by Get Method
     try{
        String username = (String)arg0[0];
        String password = (String)arg0[1];
        String link = "http://XXX.XXX.X.X/XXX/ins.php?username="
        +username+"&password="+password;
        URL url = new URL(link);
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();
        request.setURI(new URI(link));
        HttpResponse response = client.execute(request);
        BufferedReader in = new BufferedReader
       (new InputStreamReader(response.getEntity().getContent()));

       StringBuffer sb = new StringBuffer("");
       String line="";
       while ((line = in.readLine()) != null) {
          sb.append(line);
          break;
        }
        in.close();
        return sb.toString();
  }catch(Exception e){
     return new String("Exception: " + e.getMessage());
  }
  }
  else{
     try{
        String username = (String)arg0[0];
        String password = (String)arg0[1];
        String link="http://XXX.XXX.X.X/XXX/sel.php";
        String data  = URLEncoder.encode("username", "UTF-8") 
        + "=" + URLEncoder.encode(username, "UTF-8");
        data += "&" + URLEncoder.encode("password", "UTF-8") 
        + "=" + URLEncoder.encode(password, "UTF-8");
        URL url = new URL(link);
        URLConnection conn = url.openConnection(); 
        conn.setDoOutput(true); 
        OutputStreamWriter wr = new OutputStreamWriter
        (conn.getOutputStream()); 
        wr.write( data ); 
        wr.flush(); 
        BufferedReader reader = new BufferedReader
        (new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line = null;
        // Read Server Response
        while((line = reader.readLine()) != null)
        {
           sb.append(line);
           break;
        }
        return sb.toString();
     }catch(Exception e){
        return new String("Exception: " + e.getMessage());
     }
  }
 }
@Override
protected void onPostExecute(String result){
  this.statusField.setText("Login Successful");
  this.roleField.setText(result);
  this.sampleField.setText(result);

}
}

my select.php file (sel.php):

<?php
$con=mysqli_connect("localhost","root","","db_name");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysqli_query($con,"SELECT role,sample FROM table1 WHERE
username='$username' and password='$password'");

$row = mysqli_fetch_array($result);
$data = $row[0];
if($data){
echo $data;
}
mysqli_close($con);
?>

This is where your problem is:

@Override
protected void onPostExecute(String result){
  this.statusField.setText("Login Successful");
  this.roleField.setText(result);
  this.sampleField.setText(result);

}

If you want different values for sampleField and roleField, you should set different values.

Update

I see where your other problem is. In the un-updated PHP source, you are selecting both role and sample from the database table, but you are outputting only role because $data equals $row[0]. If you want sample as well, you would need to retrieve $row[1] as well.

Or you could also use $row["role"] and $row["sample"] to get the values returned from the database table.

<?php
$con=mysqli_connect("localhost","root","","db_name");
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$username = $_POST['username'];
$password = $_POST['password'];

$result = mysqli_query($con,"SELECT role,sample FROM table1 WHERE
username='$username' and password='$password'");

$row = mysqli_fetch_array($result);

if($row){
    // returns a json object in the form
    // {"role":"<role-from-database>","sample":"<sample-from-database>"}

    $output = array("role" => $row["role"] ,"sample" => $row["sample"]);

    echo json_encode($output);
}
mysqli_close($con);
?>

With the updated PHP source, you should process the JSON object in your SigninActivity.

Update 2

@Override
protected void onPostExecute(String result){

    String role = "", sample = "";

    // read the json object with JsonReader
    JsonReader reader = new JsonReader(new StringReader(result));
    reader.beginObject();
    while (reader.hasNext()) {
      String name = reader.nextName();
      if (name.equals("role")) {
        role = reader.nextString();
      } else if (name.equals("sample")) {
        sample = reader.nextString();
      } else {
        reader.skipValue();
      }
    }
    reader.endObject();

    // set the text here
}

Let me know if this helps.