title: For each loop is not executing when uploaded at 000webhost server
body: <p>I have an application that post data to a php file in an online server. When the post is done i get a garbage of html code. In it says I have a php error and that is Invalid argument supplied for each() on line 33. However this problem does not occur if I run it  in localhost. I don't understand why this problem is occuring. So someone please help me to solve it.</p>
  
  <p>The following is my jsonparser Class</p>
  
  <pre><code>public class JSONParser {
  
      static InputStream is = null;
      static JSONObject jObj = null;
      static String json = "";
  
      // constructor
      public JSONParser() {
  
      }
  
      public JSONObject getandpostJSONFromUrl(String url, String method,JSONArray name) {
  
          // Making HTTP request
          try {
              // defaultHttpClient
              if (method == "POST") {
  
  
                  HttpParams params = new BasicHttpParams();
                  //params.setParameter("data", auth);
                  HttpClient httpclient = new DefaultHttpClient(params);
  
                  HttpPost httpPost = new HttpPost(url);
  
  
                  List&lt;NameValuePair&gt; postParams = new ArrayList&lt;NameValuePair&gt;();
                  postParams.add(new BasicNameValuePair("json", name.toString()));
  
                  for (NameValuePair nvp : postParams) {
                      String name2 = nvp.getName();
                      String value = nvp.getValue();
                      Log.d("NameValue pair content", ""+name2+""+value);
                  }
  
  
                  UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postParams,HTTP.UTF_8);
  
  
                  httpPost.setEntity(entity);
                  HttpResponse response = httpclient.execute(httpPost);
                  String responseBody = EntityUtils.toString(response.getEntity()); 
                  Log.d("",responseBody);
              }
              if (method == "GET") {
  
                  DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpPost httpPost = new HttpPost(url);
  
                  HttpResponse httpResponse = httpClient.execute(httpPost);
                  HttpEntity httpEntity = httpResponse.getEntity();
                  is = httpEntity.getContent();
  
              }
  
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          } catch (ClientProtocolException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          if (method == "POST") {
              try {
                  BufferedReader reader = new BufferedReader(
                          new InputStreamReader(is));
              } catch (Exception e) {
                  Log.e("Buffer error", "Buffer error" + e);
              }
  
          } else if (method == "GET") {
  
              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>The following is the php file on the server</p>
  
  <pre><code>&lt;?php
          header('Content-type: application/json');
          /*define('DB_NAME', 'a1422982_sshop');
                          define('DB_USER', 'root');
                          define('DB_PASSWORD', '');
                          define('DB_HOST', 'localhost');*/
  
          define('DB_NAME', 'onlineshop');
          define('DB_USER', 'shop');
          define('DB_PASSWORD', 'pass');
          define('DB_HOST', 'mysql28.000webhost.com'); 
  
  
                          $link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
  
                          if(!$link){
                          die('could not connect: '.msql_error());
                          }
  
                          $db_selected=mysql_select_db(DB_NAME, $link);
  
                          if(!$db_selected){
                          die('Can not  use '.DB_NAME.':'.mysql_error());
                          }
  
                          //var_dump(json_decode ($_POST['json'])));
  
                          if($_POST['json']){
                              $parsed = json_decode($_POST['json'],TRUE);
  
                              $i=0;
  
                              foreach ($parsed as $obj) {
                                   $ProductName = $obj['Name'];   
                                   $ProductQuantity= $obj['Quantity'];
                                   $sql="Update productlist Set Quantity='$ProductQuantity' where Name='$ProductName';";
  
                                   $retval = mysql_query( $sql, $link );
                                    if(! $retval )
                                      {
                                        die('Could not get data: ' . mysql_error());
                                      }
                                   $i++;
  
                                   echo   $ProductName." ".$ProductQuantity;
                               }
                          }else{
                              echo "empty";
                          }
  
  
  ?&gt;
  </code></pre>