Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $con = mysqli_connect("my_host", "my_user", "my_password", "my_database");
- $username = $_POST["username"];
- $password = $_POST["password"];
- $statement = mysqli_prepare($con, "SELECT * FROM user WHERE username = ? AND password = ?");
- mysqli_stmt_bind_param($statement, "ss", $username, $password);
- mysqli_stmt_execute($statement);
- mysqli_stmt_store_result($statement);
- mysqli_stmt_bind_result($statement, $userID, $name, $username, $password);
- $response = array();
- $response["success"] = false;
- while(mysqli_stmt_fetch($statement)){
- $response["success"] = true;
- $response["name"] = $name;
- $response["username"] = $username;
- $response["password"] = $password;
- }
- echo json_encode($response);
- ?>
- public void onResponse(String response) {
- try {
- JSONObject jsonResponse = new JSONObject(response);
- boolean success = jsonResponse.getBoolean("success");
- if (success) {
- String name = jsonResponse.getString("name");
- Intent intent = new Intent(LoginActivity.this, WelcomeActivity.class);
- intent.putExtra("name", name);
- intent.putExtra("username", username);
- 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(username, password, responseListener);
- RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
- queue.add(loginRequest);
- }
- 07-18 15:58:34.729 29396-29402/com.example.arthurf.tcc.app W/art: Suspending all threads took: 10.852ms
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:40)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.example.arthurf.tcc.app.LoginActivity$1$1.onResponse(LoginActivity.java:36)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.os.Looper.loop(Looper.java:148)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at java.lang.reflect.Method.invoke(Native Method)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
- 07-18 15:58:34.887 29396-29396/com.example.arthurf.tcc.app W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement