title: Android upload JSON to server error
body: <p>I am trying to upload a JSON file to my server which is using PHP. But the response is always false and I don't know why. I have tried to switch the order of information but it didn't help. </p>
  
  <p>Here is the code of my method:</p>
  
  <pre><code>public void uploadJSON(){
      try {
          JSONObject toSend = new JSONObject();
          toSend.put("user", "guri1");
          toSend.put("ts", System.currentTimeMillis() / 1000L);
          toSend.put("lat", 35.45);
          toSend.put("lon", 48.4);
          toSend.put("text", "Toto som poslal");
          toSend.put("tags", "");
          toSend.put("img", "");
          JSONTransmitter transmitter = new JSONTransmitter();
          transmitter.execute(new JSONObject[] {toSend});
  
      } catch (JSONException e) {
          e.printStackTrace();
      }
  </code></pre>
  
  <p>JSONTransmitter is basically an asynctask. Here is the code for it:</p>
  
  <pre><code>public class JSONTransmitter extends AsyncTask&lt;JSONObject, JSONObject, JSONObject&gt; {
  
  String url = "MYURLISHERE";
  
  @Override
  protected JSONObject doInBackground(JSONObject... data) {
      JSONObject json = data[0];
      HttpClient client = new DefaultHttpClient();
      HttpConnectionParams.setConnectionTimeout(client.getParams(), 100000);
  
      JSONObject jsonResponse = null;
      HttpPost post = new HttpPost(url);
      try {
          StringEntity se = new StringEntity("json="+json.toString());
          post.addHeader("content-type", "application/x-www-form-urlencoded");
          post.setEntity(se);
  
          HttpResponse response;
          response = client.execute(post);
          String resFromServer = org.apache.http.util.EntityUtils.toString(response.getEntity());
  
  
          Log.i("Response from server", resFromServer);
      } catch (Exception e) { e.printStackTrace();}
  
      return jsonResponse;
  }
  </code></pre>
  
  <p>And here is the php:</p>
  
  <pre><code>function postevent(){
  $data=json_decode(file_get_contents('php://input'), true);
  $ts=$data["ts"]*1;
  $lat=$data["lat"]*1;
  $lon=$data["lon"]*1;
  $user=mysql_real_escape_string($data["user"]);
  $text=mysql_real_escape_string($data["text"]);
  $tags=mysql_real_escape_string($data["tags"]); 
  $img=mysql_real_escape_string($data["img"]);
  if ($user!=""){
  $result=db_query("INSERT INTO events SET ts='$ts',lat='$lat',lon='$lon',user='$user',text='$text',tags='$tags',img='$img'");
  } else { $result=FALSE; }
  if($result==FALSE){
  echo "false";
  } else {
  echo "true";
  }
  }
  </code></pre>