title: Delete row from MySQL table via android
body: <p>I need to delete an item from a list view on android when clicked. The thing is, my table is not on the phone(SQLite), but on the server. So I'm using a PHP code for this. 
  I have set up an onClickListener.</p>
  
  <pre><code>list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                          @Override
                          public void onItemClick(AdapterView&lt;?&gt; a, View v,int position, long id) {
                              Show_Alert_box(v.getContext(),
                                      "Please select action.", position);
                          }
                      });
  
  public void Show_Alert_box(Context context, String message, int position) {
      final int pos = position;
  
      final AlertDialog alertDialog = new AlertDialog.Builder(context)
              .create();
      //alertDialog.setTitle(getString(R.string.app_name_for_alert_Dialog));
      alertDialog.setButton("Delete", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
  
              DBHandlerComments dbhelper = new DBHandlerComments(Comments.this);
              SQLiteDatabase db = dbhelper.getWritableDatabase();
              try{
  
                  JSONObject json2 = JSONParser.makeHttpRequest(urlDelete, "POST", params);
  
  
                  try {
                      int success = json2.getInt(TAG_SUCCESS);
  
                      if (success == 1) {
                          // successfully updated
                          Intent i = getIntent();
                          // send result code 100 to notify about product update
                          setResult(100, i);
                          finish();
                      } else {
                          // failed to update product
                      }
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
                  //adapter.notifyDataSetChanged();
                  db.close();
              }catch(Exception e){
              }
  
  
          }
      });
      alertDialog.setButton2("Cancel", new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int which) {
              alertDialog.dismiss();
          }
      });
  
      alertDialog.setMessage(message);
      alertDialog.show();
  }
  </code></pre>
  
  <p>This is my JSONParser's makehttprequest code:</p>
  
  <pre><code>public static JSONObject makeHttpRequest(String url, String method,
          List&lt;NameValuePair&gt; params) {
  
      // Making HTTP request
      try {
  
          // check for request method
          if(method == "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 == "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;
          //from here
          while ((line = reader.readLine()) != null) {
              if(!line.startsWith("&lt;", 0)){
                  if(!line.startsWith("(", 0)){
                      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>`
  And this is my PHP code:</p>
  
  <pre><code>$response = array();
  
  if (isset($_POST['id'])) {
  $id = $_POST['id'];
  
  // include db connect class
  $db = mysql_connect("localhost","tbl","password");
  
  if (!$db) {
  
      die('Could not connect to db: ' . mysql_error());
  
  }
  
  
  //Select the Database
  
  mysql_select_db("shareity",$db);
  
  // mysql update row with matched id
  $result = mysql_query("DELETE FROM comments_activities WHERE id = $id");
  
  // check if row deleted or not
  if (mysql_affected_rows() &gt; 0) {
      // successfully updated
      $response["success"] = 1;
      $response["message"] = "Product successfully deleted";
  
      // echoing JSON response
      echo json_encode($response);
  } else {
      // no product found
      $response["success"] = 0;
      $response["message"] = "No product found";
  
      // echo no users JSON
      echo json_encode($response);
  }
  } else {
  // required field is missing
  $response["success"] = 0;
  $response["message"] = "Required field(s) is missing";
  
  // echoing JSON response
  echo json_encode($response);
  }
  </code></pre>
  
  <p>I'm adding the params like this: </p>
  
  <pre><code>            params.add(new BasicNameValuePair(KEY_ID, id));
              params.add(new BasicNameValuePair(KEY_AID, aid));
              params.add(new BasicNameValuePair(KEY_ANAME, an));
              params.add(new BasicNameValuePair(KEY_EVENT, ev));
              params.add(new BasicNameValuePair(KEY_COMMENT, cb));
              params.add(new BasicNameValuePair(KEY_USER, cby));
              params.add(new BasicNameValuePair(KEY_TIME, cd));
  </code></pre>
  
  <p>I don't get any result. Can I know why?</p>