title: Login problems in android: fields are returning empty
body: <p>I am currently creating and android application for our thesis. I'm about finished with the app when I started having problems with the login. The fields are accepting the input when I try to toast it, but sends me a "Fields are empty" response when i send the data to the server. I got stuck working on this, so any help would be truly appreciated.</p>
  
  <p><strong>This is my JSONParser class:</strong></p>
  
  <pre><code>public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
  
      // constructor
      public JSONParser() {
  
      }
  
      // function get json from url
      // by making HTTP POST or GET mehtod
      public JSONObject makeHttpRequest(String url, String method,
          List&lt;NameValuePair&gt; params) {
  
          // Making HTTP request
          try {
  
              // check for request method
              if(method.equals("POST"){
                  // request method is POST
                  // defaultHttpClient
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
                  httpPost.setEntity(new UrlEncodedFormEntity(params));
  
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
  
              } else if (method.equals("GET") {
                  // request method is GET
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  String paramString = URLEncodedUtils.format(params, "utf-8");
                  url += "?" + paramString;
                  HttpGet httpGet = new HttpGet(url);
  
                  HttpResponse httpResponse = httpClient.execute(httpGet);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
              }           
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          try {
              BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
              StringBuilder sb = new StringBuilder();
              String line = null;
              while ((line = reader.readLine()) != null) {
                  sb.append(line + "\n");
              }
              is.close();
              json = sb.toString();
          } catch (Exception e) {
              Log.e("Buffer Error", "Error converting result " + e.toString());
          }
  
          // try parse the string to a JSON object
          try {
              jObj = new JSONObject(json);
          } catch (JSONException e) {
              Log.e("JSON Parser", "Error parsing data " + e.toString());
          }
  
          // return JSON String
          return jObj;
      }
  }
  </code></pre>
  
  <p><strong>This is my login asynctask:</strong></p>
  
  <pre><code>class AttemptLogin extends AsyncTask&lt;String, String, String&gt; {
  
      /**
       * Before starting background thread Show Progress Dialog
       * */
      boolean failure = false;
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(Login.this);
          pDialog.setMessage("Attempting login...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(true);
          pDialog.show();   
      }
  
      @Override
      protected String doInBackground(String... args) {
  
          int success;
          String emailaddress = EADD.getText().toString();
          String password = PASS.getText().toString();
  
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("mem_email", emailaddress));
          params.add(new BasicNameValuePair("mem_password", password));
  
          Log.d("request!", "starting");
  
          JSONObject json = jsonParser.makeHttpRequest("http://builtcycles.com/built_mobile/login.php", "POST", params);
  
          // check your log for json response
          Log.d("Login attempt", json.toString());
          // json success tag
          try{
              success = json.getInt("success");
  
              if (success == 1) {
                  String memberId = json.getString("id");
                  String memberName = json.getString("uid");
  
                  Log.d("Login Successful!", json.toString());
                  pDialog.dismiss();
  
                  intent = new Intent(Login.this, MainActivity.class);
  
                  intent.putExtra("id", memberId);
                  intent.putExtra("uid", memberName);
  
                  startActivity(intent);
                  finish();
  
                  return json.getString("message");       
              } else {
                  Log.d("Login Failure!", json.getString("message"));
                  return json.getString("message");
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return null;
      }
  
      /**
       * After completing background task Dismiss the progress dialog
       * **/
  
      @Override
      protected void onPostExecute(String file_url) {
  
          pDialog.dismiss();
  
          if (file_url != null) {
              Toast.makeText(Login.this, file_url, Toast.LENGTH_SHORT).show();
          }
      }
  }
  </code></pre>
  
  <p><strong>And this is my login php:</strong></p>
  
  <pre><code>&lt;?php
      $response = array();
      if (!empty($_POST)) {
  
          $email= $_POST['mem_email'];
  
          // include db connect class
          require_once __DIR__ . '/db_connect.php';
  
          // connecting to db
          $db = new DB_CONNECT();
  
          // mysql inserting a new row
          $result = mysql_query("SELECT * from tblmembers where mem_email='$email'");
  
          if (mysql_num_rows($result) &gt; 0) {
              while ($row = mysql_fetch_array($result)) {
                  $response["id"] = $row["mem_id"];
                  $response["uid"] = $row["mem_fname"];
  
                  if ($row["mem_active"]==1) {
                      if (md5($_POST['mem_password'])===$row['mem_password']) {
  
                          $response["success"] = 1;
                          $response["message"] = "Login successfully!";
  
                          echo json_encode($response);
                      } else {
  
                          $response["success"] = 0;
                          $response["message"] = "Invalid email or password";
  
                          echo json_encode($response);                             
                      }
                  } else {
                      $response["success"] = 3;
                      $response["message"] = "Check your email for verification! Thanks.";
  
                      echo json_encode($response); 
                  }
              }
          } else {
              // no products found
              $response["success"] = 4;
              $response["message"] = "No user found";
  
              // echo no users JSON
              echo json_encode($response);
          }   
      } else {
          $response["success"] = 4;
          $response["message"] = "Fields are empty.";
  
          // echo no users JSON
          echo json_encode($response);
      }
  ?&gt;
  </code></pre>
  
  <p>I have changed method == "POST"/"GET" into method.equals("POST"). Still, I am not able to send the data to the server. Is the problem coming from the jsonparser class, or in the doinbackground() of the asynctask? </p>