title: Executing PHP scripts using a button from Android app
body: <p>I am trying to make a simple app with two buttons each of which would execute a PHP script on my DB, on localhost. So far i have the php script working as intended (tested in browser):</p>
  
  <pre><code>&lt;?php
  require 'Connect.php'; // connects to DB
  
  $query = "UPDATE tracker_database
  SET tracker_logged_in = '1'
  WHERE tracker_username = 'tracker01'";
  
  if(mysqli_query($conn, $query))
  {
      echo'Success';
  } else {
      echo'not executed';
  }
  ?&gt;
  </code></pre>
  
  <p>here I have the app's OnClickListener</p>
  
  <pre><code>public void addListenerOnExeBtn() {
      btn_exe = (Button) findViewById(R.id.btn_exe);
      btn_exe.setOnClickListener(
              new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      String link = "http://10.0.3.2/path/to/my/script.php"; //using this IP for Genymotion emulator
                      new updateData().execute(link);
                      Toast.makeText(MainActivity.this, "Executed", Toast.LENGTH_LONG).show();
                  }
              }
      );
  }
  </code></pre>
  
  <p>And as far as I understand you need to use AsyncTask to access the scripts</p>
  
  <pre><code>private class updateData extends AsyncTask &lt;String, Void, Void&gt; {
  
      @Override
      protected Void doInBackground(String... params) {
          try {
              URL url = new URL(params[0]);
              HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
              urlConn.connect();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
          return null;
      }
  }
  </code></pre>
  
  <p>So my problem is that when I run my app and click the btn_exe it prints out the Toast "Executed" but when I refresh my DB there are no changes, and yes I put the</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  </code></pre>
  
  <p>in my AndroidManifest.xml. I can't find anything wrong in the logcat, no errors, nothing. Anyone has any ideas?</p>