First, I have a working user registration and login page which is connected to UserAccTable table in my database. The user will login using their email add and password. What i need is to fetch the UserID after logging in, then pass it to another page using intent for the fore key of an another table.
Here is my php code:
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
include 'DatabaseConfigThesis.php';
$con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
$email = $_POST['Email'];
$password = $_POST['Password'];
$Sql_Query = "select * from UserAccTable where Email = '$email' and Password = '$password' ";
$check = mysqli_fetch_array(mysqli_query($con,$Sql_Query));
echo "Hello, " . $check['UserID'] . " (" . $check['UserID'] . ").";
if(isset($check)){
echo "Data Matched";
}
else{
echo "Invalid Username or Password Please Try Again !";
}
}else{
echo "Check Again";
}
mysqli_close($con);
?>
I used this code echo "Hello, " . $check['UserID'] . " (" . $check['UserID'] . ")."; To check if it really fetch the UserID which actually works but i don't know how to pass it to android studio. I heard about using Sessions but unfortunately, I don't know how to use it.
BTW here's my login page code in android studio
public class UserLog extends AppCompatActivity {
// Creating EditText.
EditText Email, Password;
// Creating button;
Button LoginButton;
// Creating Volley RequestQueue.
RequestQueue requestQueue;
// Create string variable to hold the EditText Value.
String EmailHolder, PasswordHolder;
// Creating Progress dialog.
ProgressDialog progressDialog;
// Storing server url into String variable.
String HttpUrl = "http://192.168.254.112:81/UserAccDatabaseTable/UserLogin.php";
Boolean CheckEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_log);
    // Assigning ID's to EditText.
    Email = (EditText) findViewById(R.id.etUserEmail);
    Password = (EditText) findViewById(R.id.etUserPass);
    // Assigning ID's to Button.
    LoginButton = (Button) findViewById(R.id.btnUserLogin);
    // Creating Volley newRequestQueue .
    requestQueue = Volley.newRequestQueue(UserLog.this);
    // Assigning Activity this to progress dialog.
    progressDialog = new ProgressDialog(UserLog.this);
    // Adding click listener to button.
    LoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            CheckEditTextIsEmptyOrNot();
            if (CheckEditText) {
                UserLogin();
            } else {
                Toast.makeText(UserLog.this, "Please fill all form fields.", Toast.LENGTH_LONG).show();
            }
        }
    });
}
// Creating user login function.
public void UserLogin() {
    // Showing progress dialog at user registration time.
    progressDialog.setMessage("Please Wait");
    progressDialog.show();
    // Creating string request with post method.
    StringRequest stringRequest = new StringRequest(Request.Method.POST, HttpUrl,
            new Response.Listener<String>() {
                @Override
                public void onResponse(String ServerResponse) {
                    // Hiding the progress dialog after all task complete.
                    progressDialog.dismiss();
                    // Matching server responce message to our text.
                    if(ServerResponse.equalsIgnoreCase("Data Matched")) {
                        // If response matched then show the toast.
                        Toast.makeText(UserLog.this, "Logged In Successfully", Toast.LENGTH_LONG).show();
                        // Finish the current Login activity.
                        finish();
                        // Opening the user profile activity using intent.
                        Intent intent = new Intent(UserLog.this, UserChoose.class);
                        // Sending User Email to another activity using intent.
                        intent.putExtra("UserEmailTAG", EmailHolder);
                        startActivity(intent);
                    }
                    else {
                        // Showing Echo Response Message Coming From Server.
                        Toast.makeText(UserLog.this, ServerResponse, Toast.LENGTH_LONG).show();
                    }
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError volleyError) {
                    // Hiding the progress dialog after all task complete.
                    progressDialog.dismiss();
                    // Showing error message if something goes wrong.
                    Toast.makeText(UserLog.this, volleyError.toString(), Toast.LENGTH_LONG).show();
                }
            }) {
        @Override
        protected Map<String, String> getParams() {
            // Creating Map String Params.
            Map<String, String> params = new HashMap<String, String>();
            // Adding All values to Params.
            // The firs argument should be same sa your MySQL database table columns.
            params.put("Email", EmailHolder);
            params.put("Password", PasswordHolder);
            return params;
        }
    };
    // Creating RequestQueue.
    RequestQueue requestQueue = Volley.newRequestQueue(UserLog.this);
    // Adding the StringRequest object into requestQueue.
    requestQueue.add(stringRequest);
}
public void CheckEditTextIsEmptyOrNot() {
    // Getting values from EditText.
    EmailHolder = Email.getText().toString().trim();
    PasswordHolder = Password.getText().toString().trim();
    // Checking whether EditText value is empty or not.
    if (TextUtils.isEmpty(EmailHolder) || TextUtils.isEmpty(PasswordHolder)) {
        // If any of EditText is empty then set variable value as False.
        CheckEditText = false;
    } else {
        // If any of EditText is filled then set variable value as True.
        CheckEditText = true;
    }
}
}
I hope someone could help me. I know my php code is prone to SQL injection, I will fix it after i finished this problem. Thank you
 
     
     
    