im trying this new method Ion. with PDO and I got stuck where I want to get value inside JsonObject. I previously used String request with msqli but I find Ion. and cases more organized and PDO more safe.
whenever I try to add any code to java its just break and don't work as if no connection same with PHP so I got stuck
part where I'm stuck at is LOG_IN_SUCCESS as I need to get user id for session manager as $row doesn't show in java only the case "LOG_IN_SUCCESS" i also added case"LOG_IN_SUCCESS ": case"0":{code break;} but i didnt work
I tried to add new string for case"0"which contain user Id but code just break
java
private void loginbtn(final String email, final String password) { Ion.with(getApplicationContext()) .load(HOST) .setBodyParameter("susers_semails", email) .setBodyParameter("susers_spasswords", password) .asJsonObject() .setCallback(new FutureCallback<JsonObject>() { @Override public void onCompleted(Exception e, JsonObject result) { try { String completed = result.get("LOGIN").getAsString(); switch (completed){ case "Email_Doesnt_Exist": edtemail.setError("Email Doesnt Exist"); loginbtn.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); break; case "Log_In_Success": Intent intent = new Intent(LoginActivity.this, HomeSearchActivity.class); startActivity(intent); finish(); loginbtn.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); Toast.makeText(LoginActivity.this, completed, Toast.LENGTH_LONG); Log.d(TAG, "onCompleted: " + completed); break; case "Log_In_Failed": edtpassword.setError("Incorrect Password"); loginbtn.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); break; default: Toast.makeText(getApplicationContext(), "Ops! Error Occurred m", Toast.LENGTH_LONG).show(); loginbtn.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); break; } }catch (Exception error){ Toast.makeText(getApplicationContext(), "Please Check Connection And Try Again", Toast.LENGTH_LONG).show(); loginbtn.setVisibility(View.VISIBLE); progressBar.setVisibility(View.GONE); } } }); }
php
$susers_semails = $_POST['susers_semails']; $susers_spasswords = $_POST['susers_spasswords']; $stmt = $PDO->prepare("SELECT susers_sids,susers_semails,susers_spasswords FROM userstbl WHERE susers_semails = :USER_EMAIL" ); $stmt->bindParam(':USER_EMAIL',$susers_semails); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); if (!empty($row)) { if (password_verify($susers_spasswords, $row['susers_spasswords'])) { $returnApp = array( 'LOGIN' => 'Log_In_Success',$row); echo json_encode($returnApp); } else { $returnApp = array( 'LOGIN' => 'Log_In_Failed'); echo json_encode($returnApp); } } else { $returnApp = array( 'LOGIN' => 'Email_Doesnt_Exist'); echo json_encode($returnApp); }
JSON
{ 0: { susers_sids: "3" }, LOGIN: "Log_In_Success" }
https://stackoverflow.com/questions/65386020/how-to-get-value-inside-jsonobject December 21, 2020 at 07:59AM
没有评论:
发表评论