Try to search your question here, if you can't find : Ask Any Question Now ?

org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject while connecting to phpmyadmin

HomeCategory: stackoverfloworg.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject while connecting to phpmyadmin
Avatarbhawya asked 1 month ago

I want to connect android studio with phony admin.I use
https://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ tutorial for connecting ,I got error about type java.lang.String cannot be converted to JSONObject,can someone help me in solving the issue.Thanks
Run shows:

    <b>Fatal error</b>:  Uncaught Error: Call to a member function bind_param() on boolean in /Applications/XAMPP/xamppfiles/htdocs/android_login_api/include/DB_Functions.php:36
    Stack trace:
    #0 /Applications/XAMPP/xamppfiles/htdocs/android_login_api/register.php(24): DB_Functions-&gt;storeUser('s', 's@gmail.com', '4321')
    #1 {main}
      thrown in <b>/Applications/XAMPP/xamppfiles/htdocs/android_login_api/include/DB_Functions.php</b> on line <b>36</b><br />
I/OpenGLRenderer: Davey! duration=1768ms; Flags=0, IntendedVsync=36591435466372, Vsync=36591868799688, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=36591882245782, AnimationStart=36591886127782, PerformTraversalsStart=36591889716782, DrawStart=36593162878782, SyncQueued=36593162915782, SyncStart=36593164901782, IssueDrawCommandsStart=36593164963782, SwapBuffers=36593165397782, FrameCompleted=36593206044782, DequeueBufferDuration=12416000, QueueBufferDuration=425000, 
W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
W/System.err:     at org.json.JSON.typeMismatch(JSON.java:112)
        at org.json.JSONObject.<init>(JSONObject.java:163)
        at org.json.JSONObject.<init>(JSONObject.java:176)
        at       com.example.practicetransportationapp.activity.RegisterActivityFirst$3.onResponse(RegisterActivityFirst.java:131)
W/System.err:     at com.example.practicetransportationapp.activity.RegisterActivityFirst$3.onResponse(RegisterActivityFirst.java:120)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
        at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
W/System.err:     at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6669)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I/Choreographer: Skipped 107 frames!  The application may be doing too much work on its main thread.

php code:

class DB_Functions {

private $conn;

// constructor
function __construct() {
    require_once 'DB_Connect.php';
    // connecting to database
    $db = new Db_Connect();
    $this->conn = $db->connect();
}

// destructor
function __destruct() {

}

/**
 * Storing new user
 * returns user details
 */
public function storeUser($name, $email, $password) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt

    $stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
    $stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
    $result = $stmt->execute();
    $stmt->close();

    // check for successful store
    if ($result) {
        $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

        return $user;
    } else {
        return false;
    }
}

/**
 * Get user by email and password
 */
public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");

    $stmt->bind_param("s", $email);

    if ($stmt->execute()) {
        $user = $stmt->get_result()->fetch_assoc();
        $stmt->close();

        // verifying user password
        $salt = $user['salt'];
        $encrypted_password = $user['encrypted_password'];
        $hash = $this->checkhashSSHA($salt, $password);
        // check for password equality
        if ($encrypted_password == $hash) {
            // user authentication details are correct
            return $user;
        }
    } else {
        return NULL;
    }
}

/**
 * Check user is existed or not
 */
public function isUserExisted($email) {
    $stmt = $this->conn->prepare("SELECT email from users WHERE email = ?");

    $stmt->bind_param("s", $email);

    $stmt->execute();

    $stmt->store_result();

    if ($stmt->num_rows > 0) {
        // user existed 
        $stmt->close();
        return true;
    } else {
        // user not existed
        $stmt->close();
        return false;
    }
}

/**
 * Encrypting password
 * @param password
 * returns salt and encrypted password
 */
public function hashSSHA($password) {

    $salt = sha1(rand());
    $salt = substr($salt, 0, 10);
    $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
    $hash = array("salt" => $salt, "encrypted" => $encrypted);
    return $hash;
}

/**
 * Decrypting password
 * @param salt, password
 * returns hash string
 */
public function checkhashSSHA($salt, $password) {

    $hash = base64_encode(sha1($password . $salt, true) . $salt);

    return $hash;
}

}

?>

1 Answers
Best Answer
AvatarAmit answered 1 month ago
Your Answer

19 + 16 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com