Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am working on an app in android studio.. it currently has a login and registration system that are linked to a database and both work perfectly.

I am now trying to carry over the user id value using SESSION in php so that the activity past the login will have all the information it needs to personalize the app. To do so I made a class called Profile that, when instantiated, retrieves and stores all user information based on the id stored as a session variable.

The profile class is accompanied by it's own php file, buildprofile.php. Any class can instantiate Profile and use to to get information (hopefully).

Currently when I attempt to instantiate Profile the app crashes. There are probably 50 different things causing this and I have changed things over and over to no avail. I started a session in the login activity and stored a session variable 'id' upon login success.

The Profile constructor (based on method in a JSONParser class):

try {
        JSONObject jobj = jsonParser.getJSONFromUrl(PROFILE_URL);
        username = jobj.getString("username");
    } catch (JSONException e) {
        e.printStackTrace();
    }

buildprofile.php:

<?php
session_start();

require("config.inc.php");

if (isset($_SESSION['id'])){
    $query = "SELECT id,email,username,bio FROM users WHERE id = :id";    
    $query_params = array(':id' => $_SESSION['id']);

    try {
        $stmt   = $db->prepare($query);
        $result = $stmt->execute($query_params);
    }
    catch (PDOException $ex) {
        $response["success"] = 0;
        $response["message"] = "Database Error1. Please Try Again!";
        die(json_encode($response));
    }
}

$row = $stmt->fetch();
json_encode($row);

?>
share|improve this question
    
For starters, json_encode() returns a string - if you don't echo it, your php script will return nothing. On another note, it's not recommended to have logic like that in a constructor. –  Sam Dufel Apr 27 at 2:37
    
oops. I echo'd it and it still crashes. Regardless of where the JSONobject is created –  Joey Hanlon Apr 27 at 3:37
    
I'd suggest editing the stack trace into your question. –  Sam Dufel Apr 28 at 1:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.