currently i am writing a login and register function for my app, i followed the tutorial on youtube and tried the same code as provided.
this is my code of loginactivity java class.
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
final EditText etUseame = (EditText) findViewById(R.id.etUseame);
final EditText etPassword = (EditText) findViewById(R.id.etPassword);
final Button bLogin= (Button) findViewById(R.id.bLogin);
final TextView RegisterLink= (TextView) findViewById(R.id.tvRegisterHere);
RegisterLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent RegisterIntent = new Intent(LoginActivity.this, RegisterActivity.class);
LoginActivity.this.startActivity(RegisterIntent);
}
});
bLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String useame = etUseame.getText().toString();
final String password = etPassword.getText().toString();
// Response received from the server
Response.Listener<String> responseListener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
boolean success = jsonResponse.getBoolean("success");
if (success) {
String useame = jsonResponse.getString("useame");
Intent intent = new Intent(LoginActivity.this, Dashboard.class);
intent.putExtra("useame", useame);
LoginActivity.this.startActivity(intent);
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
builder.setMessage("Login Failed")
.setNegativeButton("Retry", null)
.create()
.show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
};
LoginRequest loginRequest = new LoginRequest(useame, password, responseListener);
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
queue.add(loginRequest);
}
});
}
My LoginRequest java class
public class LoginRequest extends StringRequest {
private static final String LOGIN_REQUEST_URL = "https://n000000.scm.ssss.ac.uk/FYP/Login.php";
private Map<String, String> params;
public LoginRequest(String useame, String password, Response.Listener<String> listener) {
super(Method.POST, LOGIN_REQUEST_URL, listener, null);
params = new HashMap<>();
params.put("useame", useame);
params.put("password", password);
}
@Override
public Map<String, String> getParams() {
retu params;
}
}
my php file.
<?php
$con = mysqli_coect("host", "database", "password", "user");
$Useame = $_POST["useame"];
$Password = $_POST["password"];
$statement = mysqli_prepare($con, "SELECT * FROM User WHERE useame = ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $Useame, $Password);
mysqli_stmt_execute($statement);
mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $Useame, $Password);
$response = array();
$response["success"] = false;
while(mysqli_stmt_fetch($statement)){
$response["success"] = true;
$response["useame"] = $Useame;
$response["password"] = $Password;
}
print_r(json_encode($response));
?>
Finally, when i click on the login button, nothing happened on screen, in the monitor log, there is a red line
05-19 18:17:08.308 14485-14805/fyp.pau.regover E/Volley: [190] BasicNetwork.performRequest: Unexpected response code 401 for https://n000000.scm.ssss.ac.uk/FYP/Login.php
when i click on the link https://n000000.scm.ssss.ac.uk/FYP/Login.php it shows the script below.
Notice: Undefined index: User.Useame in /web/users/n000000/FYP/Login.php on line 5 Notice: Undefined index: User.Password in /web/users/n000000/FYP/Login.php on line 6 Waing: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in /web/users/n000000/FYP/Login.php on line 13 {"success":false}
it is so urgent, could anyone help me to solve this please Thanks!
