title: How to get user id from XAMPP database for Android Studio
body: <p>I'm creating an Android app that has login and register pages. After someone has logged in, they can do different tests provided by the app. How do I get their results to be stored with their user ID in the XAMPP database? I have provided the login.php, LoginActivity.java, User.java and EditProfile.java code. I have provided an example where someone might want to edit their profile and when they want to save the changes, it should be saved with their user ID. I'm struggling with it. Any help would be greatly appreciated, thank you</p>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
      $error = NULL;
  
      include_once('connection.php');
          if(isset($_POST['txtUsername']) &amp;&amp; isset($_POST['txtPassword'])){
          $username = $_POST['txtUsername'];
          $password = $_POST['txtPassword'];
  
          $query = "SELECT * FROM user WHERE username = '$username' AND password = '$password'";
  
          $result = mysqli_query($conn, $query);
  
          if($username == $error || $password == $error) {
              echo "Login Failed &lt;br&gt;";
          }
          else if($result-&gt;num_rows &gt; 0){
              if(isset($_POST['mobile']) &amp;&amp; $_POST['mobile'] == "android"){
                  echo "success";
                  exit;
              }
              echo "Login Successful";
          }
          else{
              echo "Login Failed &lt;br&gt;";
          }
      }
  ?&gt;
  
  
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Login&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Login &lt;/h1&gt;
  &lt;form action="&lt;?PHP $_PHP_SELF ?&gt;" method="post"&gt;
      Username &lt;input type="text" name="txtUsername" value="" /&gt; &lt;br/&gt;
      Password &lt;input type="password" name="txtPassword" value=""/&gt;&lt;br/&gt;
      &lt;input type="submit" name="btnSubmit" value="Login"/&gt; &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>LoginActivity.java</p>
  
  <pre><code>package com.delta.object.newandroidproject;
  
  import android.content.Intent;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.view.WindowManager;
  import android.widget.Button;
  import android.widget.EditText;
  import android.widget.Toast;
  
  import com.kosalgeek.asynctask.AsyncResponse;
  import com.kosalgeek.asynctask.PostResponseAsyncTask;
  
  import java.util.HashMap;
  
  public class LoginActivity extends AppCompatActivity implements       AsyncResponse, View.OnClickListener {
  
      EditText etUsername, etPassword;
      Button loginBtn;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
          Toolbar mToolbar = (Toolbar) findViewById(R.id.login_toolbar);
          setSupportActionBar(mToolbar);
          this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
          etUsername = (EditText) findViewById(R.id.etUsername);
          etPassword = (EditText) findViewById(R.id.etPassword);
          loginBtn = (Button) findViewById(R.id.email_login_button);
          loginBtn.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          HashMap postData = new HashMap();
          postData.put("mobile", "android");
          postData.put("txtUsername", etUsername.getText().toString());
          postData.put("txtPassword", etPassword.getText().toString());
  
          PostResponseAsyncTask task = new PostResponseAsyncTask(this, postData);
          task.execute("http://10.0.3.2/androidproject/login.php");
  
      }
  
      @Override
      public void processFinish(String result) {
          if (result.equals("success")) {
              Intent i = new Intent(this, TestActivity.class);
              startActivity(i);
          }
          else{
              Toast.makeText(this, "Login Failed", Toast.LENGTH_LONG).show();
          }
  
      }
  
      public void registerClick(View view) {
          Intent i = new Intent(LoginActivity.this, SignUpActivity.class);
          startActivity(i);
      }
  }
  </code></pre>
  
  <p>User.php</p>
  
  <pre><code>package com.delta.object.newandroidproject;
  
  import com.google.gson.annotations.SerializedName;
  
  public class User {
  
      @SerializedName("user_id")
      public int user_id;
  
      @SerializedName("name")
      public String name;
  
      @SerializedName("gender")
      public String gender;
  
      @SerializedName("username")
      public String username;
  
      @SerializedName("password")
      public String password;
   }
  </code></pre>
  
  <p>EditProfile.java</p>
  
  <pre><code>package com.delta.object.newandroidproject;
  
  import android.content.Intent;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  
  
  public class EditProfile extends AppCompatActivity {
  
      EditText etName, etPassword, etUsername;
      Button submitBtn;
      RadioGroup rg;
      private User user;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.edit_profile);
          Toolbar mToolbar = (Toolbar) findViewById(R.id.edit_profile_toolbar);
          setSupportActionBar(mToolbar);
      }
  
      public void editProfileSave(View view) {
          Intent i = new Intent(EditProfile.this, TestActivity.class);
          startActivity(i);
      }
  
      public void cancelClick(View view) {
          Intent i = new Intent(EditProfile.this, TestActivity.class);
          startActivity(i);
      }
  }
  </code></pre>