title: POST parameter to php using AsyncHttpClient
body: <p>I want to delete a row from my database using MySQL. I need to pass the parameter I want to delete from my Android app to the php script. I am using AsyncHttpClient but nothings happens, I get an OK message in my log.</p>
  
  <p>I have tried changing the value <code>username="$name"</code> in my php script to an existing value in the table and it works correctly, the row is deleted. I think my error is in passing the value from Android to php.</p>
  
  <p>deleteuser.php script:</p>
  
  <pre><code>&lt;?php
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = 'root';
  $conn = mysql_connect($dbhost, $dbuser, $dbpass);
  if(! $conn )
  {
    die('Could not connect: ' . mysql_error());
  }
  
  $name = $_GET["username"];
  
  $sql = 'DELETE FROM usuarios
          WHERE username="$name"';
  
  mysql_select_db('etsiitcast_db');
  $retval = mysql_query( $sql, $conn );
  if(! $retval )
  {
    die('Could not delete data: ' . mysql_error());
  }
  echo "Deleted data successfully\n";
  mysql_close($conn);
  ?&gt;
  </code></pre>
  
  <p>Android code:</p>
  
  <pre><code> final AsyncHttpClient client = new AsyncHttpClient();
  
          Button delete = (Button) rootView.findViewById(R.id.delete);
          delete.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  RequestParams params = new RequestParams();
                  params.put("username", user);
  
                  client.post("http://" + IP_Server + "/etsiitcast_db/deleteuser.php", params, new AsyncHttpResponseHandler() {
  
                      @Override
                      public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                          Log.d("OK", "Usuario eliminado");
                          getActivity().finish();
                      }
  
                      @Override
                      public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
                          Log.d("ERROR", "Se ha producido un error al eliminar al usuario");
                      }
                  });
              }
          });
  </code></pre>
  
  <p>Where <code>user</code> is a String which value is the username:</p>
  
  <pre><code>Bundle extras = getActivity().getIntent().getExtras();
  
  if (extras != null){
     user = extras.getString("user");
  } else {
     user = "error";
  }
  </code></pre>
  
  <p>UPDATE:</p>
  
  <p>In my Android code I have changed this line:</p>
  
  <pre><code>client.get("http://" + IP_Server + "/etsiitcast_db/deleteuser.php", params, new AsyncHttpResponseHandler() { [...] }
  </code></pre>
  
  <p>New php script:</p>
  
  <pre><code>&lt;?php
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = 'root';
  $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
  if(! $conn )
  {
    die('Could not connect: ' . mysqli_error());
  }
  
  $name = $_GET["username"];
  $name = $mysqli-&gt;real_escape_string($name);
  
  $sql = 'DELETE FROM usuarios
          WHERE username="$name"';
  
  mysqli_select_db('etsiitcast_db');
  $retval = mysqli_query( $sql, $conn );
  if(! $retval )
  {
    die('Could not delete data: ' . mysqli_error());
  }
  echo "Deleted data successfully\n";
  mysqli_close($conn);
  ?&gt;
  </code></pre>