title: Getting data from mysql database using php in android
body: <p>I am trying to access an individual player in the database, I am getting the response {"success":0,"message":"Required field(s) is missing"} but this is wrong and should be outputting a single player field.</p>
  
  <p>I  think the problem is with the php code but I am not certain. Any help is greatly appreciated, thanks.</p>
  
  <p>php code - </p>
  
  <pre><code>&lt;?php
  
  require('db_connection.php');
  
  // check for post data
  if (isset($_GET["playerid"])) {
  $playerid = $_GET['playerid'];
  
  // get a player from week1 table
  $result = mysql_query("SELECT *FROM week1 WHERE playerid = $playerid");
  
  if (!empty($result)) {
      // check for empty result
      if (mysql_num_rows($result) &gt; 0) {
  
          $result = mysql_fetch_array($result);
  
          $player = array();
          $player["playerid"] = $result["playerid"];
          $player["score"] = $result["score"];
          $player["lastholeplayed"] = $result["lastholeplayed"];
          $player["overall"] = $result["overall"];
  
          // success
          $response["success"] = 1;
  
          // user node
          $response["player"] = array();
  
          array_push($response["player"], $player);
  
          // echoing JSON response
          echo json_encode($response);
      } else {
          // no player found
          $response["success"] = 0;
          $response["message"] = "No player found";
  
          // echo no users JSON
          echo json_encode($response);
      }
  } else {
      // no player found
      $response["success"] = 0;
      $response["message"] = "No player 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);
  }
  ?&gt;
  </code></pre>
  
  <p>related java class - </p>
  
  <pre><code>public class InputScores extends Activity {
  
  
  // Progress Dialog
      private ProgressDialog pDialog;
  
      // Creating JSON Parser object
  
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; holesList;
  
      // url to get all products list
      private static String url_update_players = "http://192.168.2.4/realdeal/getplayer.php";
  
      // JSON Node names
  
  
      // products JSONArray
      JSONArray courseone = null;
  
      @Override
      public void onDestroy() {
          super.onDestroy();
          if (pDialog != null) {
              pDialog.cancel();
          }
      }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.setContentView(R.layout.updatescores);
  
      Intent i = getIntent();
      i.getStringExtra("playerid");
  
      //String playerid = i.getStringExtra("playerid");
      //System.out.println(playerid);
      //TextView myTextView = (TextView)findViewById(R.id.);
      //myTextView.setText(playerid);
      //String playerid = "999";
      new loadplayerdetails().execute();
  
  }
  /**
   * Background Async Task to Load all holes by making HTTP Request
   * */
  class loadplayerdetails extends AsyncTask&lt;String, String, String&gt; {
  
  
  
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(InputScores.this);
          pDialog.setMessage("Loading holes. Please wait...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
  
      /**
       * getting All holes from url
       * */
      protected String doInBackground(String... params) {
  
          try {
              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new HttpPost(url_update_players);
  
              List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(
                      2);
              String playerid ="5";
              nameValuePairs.add(new BasicNameValuePair("playerid", playerid));
  
  
  
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
              ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler();
  
              String response = httpclient.execute(httppost,
                      responseHandler);
              // you will get json string here
  
              // check here your getting json string in logcat.
              Log.d("response", response);
  
  
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          return null;
      }
      /**
       * After completing background task Dismiss the progress dialog
       * **/
      protected void onPostExecute(String file_url) {
          // dismiss the dialog after getting all players
          if (pDialog.isShowing()) {
              pDialog.dismiss();
          }
  
  
      }
  
  }
  </code></pre>
  
  <p>}</p>