title: post to php in android always return null
body: <p>I have problem posting to my php. 
  I try to post data to my php but it allways return null.
  I don't know it's from my android code or php that I get null pointer.
  can any one tell me where is the problem.
  thanks.
  this is my php code:</p>
  
  <pre><code>     &lt;?php
  
  $json = file_get_contents("php://input");
  $data = json_decode($json, true);
  
  $function = $data['function'];
  
  switch ($function) {
      case'get_my_ads':
          $user_id = $data['user_id'];
          $query = "SELECT * FROM `register_ads` WHERE `user_id` = '$user_id' ";
          $query = mysqli_query(connect(), $query);
          $result = array();
  
          while($row = $query-&gt;fetch_assoc()){
              $html ='
              &lt;table style="direction: rtl;text-align: right"&gt;
                  &lt;tr&gt;
                      &lt;td&gt;نام واحد:&lt;/td&gt;
                      &lt;td&gt;'.$row["name_vahed"].'&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;زمینه فعالیت:&lt;/td&gt;
                      &lt;td&gt;'.$row["zamine"].'&lt;/td&gt;
                  &lt;/tr&gt;
  
              &lt;/table&gt;';
              /*$tmp['name_vahed']= $row["name_vahed"];
              $tmp['zamine']    = $row["zamine"];
              $tmp['shoar']     = $row["shoar"];
              $tmp['ostan']     = $row["ostan"];
              $tmp['shahr']     = $row["shahr"];
              $tmp['adress']    = $row["adress"];
              $tmp['tel']       = $row["tel"];
              $tmp['mobile']    = $row["mobile"];
              $tmp['web']       = $row["web"];*/
              $result[]         =$html;
          }
  
          break;
      case'register_ads':
          $user_id = $data['user_id'];
          $name_vahed = $data['name_vahed'];
          $zamine = $data['zamine'];
          $shoar = $data['shoar'];
          $address = $data['address'];
          $ostnha = $data['ostnha'];
          $shahr = $data['name_vahed'];
          $tel = $data['tel'];
          $mobile = $data['mobile'];
          $email = $data['email'];
          $web = $data['web'];
  
          $query = "INSERT INTO register_ads (`id` ,`user_id`,`name_vahed` ,`zamine` ,`shoar` ,`ostan` ,`shahr` ,`adress`,`tel`,`mobile`,`email`,`web`)
                          VALUES (
                                    NULL ,'$user_id', '$name_vahed', '$zamine', '$shoar', '$ostnha', '$shahr', '$address','$tel','$mobile','$email','$web'
                          );";
          $query = mysqli_query(connect(), $query);
  
          $result = array('result'=&gt;'ok');
          break;
      case 'update_user_info':
          $user_id = $data['user_id'];
          $name = $data['name'];
          $username = $data['username'];
          $family = $data['family'];
          $email = $data['email'];
          $password = $data['password'];
          $tel = $data['tel'];
  
          if($user_id == "")
              $query = "INSERT INTO `users` (`id` ,`username` ,`password` ,`name` ,`family` ,`email` ,`tel`)
                          VALUES (
                          NULL , '$username', '$password', '$name', '$family', '$email', '$tel'
                          );";
          else
              $query = "update `users` set name = '$name', family='$family', email='$email', `password`='$password', tel='$tel'  where id= $user_id";
  
          $query = mysqli_query(connect(), $query);
  
          $result = array('result'=&gt;$query);
  
          break;
      case'user_info':
          $user_id = $data['user_id'];
  
          $query = "SELECT * FROM `users` WHERE `id` = '$user_id' ";
          $query = mysqli_query(connect(), $query);
  
          $result = array();
  
          while($row = $query-&gt;fetch_assoc()){
              $tmp['id']       = $row["id"];
              $tmp['username'] = $row["username"];
              $tmp['password'] = $row["password"];
              $tmp['name']   = $row["name"];
              $tmp['family'] = $row["family"];
              $tmp['email']  = $row["email"];
              $tmp['tel']    = $row["tel"];
              $result[]      =$tmp;
          }
          break;
      case'login':
          $username = $data['username'];
          $password = $data['password'];
          $query = "SELECT * FROM `users` WHERE `username` = '$username' AND  `password` = '$password' ";
          $query = mysqli_query(connect(), $query);
  
          $result = array();
  
          while($row = $query-&gt;fetch_assoc()){
              $tmp['id']       = $row["id"];
              $tmp['username'] = $row["username"];
              $tmp['password'] = $row["password"];
              $tmp['name']   = $row["name"];
              $tmp['family'] = $row["family"];
              $tmp['email']  = $row["email"];
              $tmp['tel']    = $row["tel"];
              $result[]      =$tmp;
          }
          break;
      case'search':
          $search = $data['search'];
          $type    = $data['type'];
          $query = "SELECT * FROM `categories` WHERE type = $type AND  `name` LIKE '%".$search."%'";
          $query = mysqli_query(connect(), $query);
  
          $result = array();
          while($row = $query-&gt;fetch_assoc()){
              $tmp['id'] = $row["id"];
              $tmp['name'] = $row["name"];
              $tmp['parent'] = $row["parent"];
              $tmp['image_id'] = $row["image_id"];
              $tmp['content'] = $row["content"];
              $tmp['type'] = $row["type"];
              $tmp['html'] = $row["html"];
              $result[]=$tmp;
          }
          break;
      case'categories':
          $id      = $data['id'];
          $parent  = $data['parent'];
          $type    = $data['type'];
          $query = "SELECT * FROM `categories` where parent = $parent AND type = $type";
          $query = mysqli_query(connect(), $query);
  
          $result = array();
          while($row = $query-&gt;fetch_assoc()){
              $tmp['id'] = $row["id"];
              $tmp['name'] = $row["name"];
              $tmp['parent'] = $row["parent"];
              $tmp['image_id'] = $row["image_id"];
              $tmp['content'] = $row["content"];
              $tmp['type'] = $row["type"];
              $tmp['html'] = $row["html"];
              $result[]=$tmp;
          }
          break;
  }
  function connect(){
      $link = mysqli_connect("localhost", "root", "a", "and");
      $link-&gt;set_charset("utf8");
      return $link;
  }
  echo json_encode($result);
  
  ?&gt;
  </code></pre>
  
  <p>and this one is my android:</p>
  
  <pre><code>HttpClient httpclient = new DefaultHttpClient();
                  HttpPost httppost = new HttpPost("http://www.hamodeveloper.ir/android.php");
                  String responseBody;
                  try{
                  List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);
                  nameValuePairs.add(new BasicNameValuePair("function","get_my_ads"));
                  nameValuePairs.add(new BasicNameValuePair("user_id","104"));
                  httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                  HttpResponse response = httpclient.execute(httppost);
                  responseBody = EntityUtils.toString(response.getEntity());
  
                  Log.e("Respons", responseBody);
                  }
                  catch (ClientProtocolException e) {
                      // TODO Auto-generated catch block
                  } 
                  catch (IOException e) {
                      // TODO Auto-generated catch block
                  }
  </code></pre>