2

I want to add a user_photo (user image URL) field to my UserCake PHP based website, do you know this script?

I know how to add the field to the register page, that adds the URL to the db, but I don't know how to use it as the display name: when I put &loggedInUser->displayname, it returns, for example, GrupoActemp.

I want to put &loggedInUser->picture, &loggedInUser->image or &loggedInUser->photo, that it returns, for example, http://www.imageserver.com/directory/image.png.

Info: db table's called user_photo

juancrrn
  • 215
  • 3
  • 11

1 Answers1

2

Guess what, I just had this issue and solved this just now. I had to back-trace all objects and then got the thing. After adding the field to the register.ph and newuser class,

  • go to models/ funcs.php , find the function fetchUserDetails ( line ~ 318 ). Add your field in $stmt variable (line ~ 345).
  • add it again to line (~354, ~456).
  • go to login.php, go to line (~ 60 ) and set add your variable at the end of the other variables (under the comment - Transfer some db data to the session object)

Thats it. use this code to check if you got the fields you wanted or not :

<pre>
    <?php print_r(get_object_vars($loggedInUser)); ?>
</pre>

For Example, I wanted to add dob (date Of Birth ) field, after adding the values to register, new user class, and func.php files,login file, my files looked like this:

login.php

//Construct a new logged in user object
//Transfer some db data to the session object
$loggedInUser = new loggedInUser();
$loggedInUser->email = $userdetails["email"];
$loggedInUser->user_id = $userdetails["id"];
$loggedInUser->hash_pw = $userdetails["password"];
$loggedInUser->title = $userdetails["title"];
$loggedInUser->displayname = $userdetails["display_name"];
$loggedInUser->username = $userdetails["user_name"];
$loggedInUser->dob = $userdetails["dob"];

funcs.php

//Retrieve complete user information by username, token or ID
function fetchUserDetails($username=NULL,$token=NULL, $id=NULL)
{
    if($username!=NULL) {
        $column = "user_name";
        $data = $username;
    }
    elseif($token!=NULL) {
        $column = "activation_token";
        $data = $token;
    }
    elseif($id!=NULL) {
        $column = "id";
        $data = $id;
    }
    global $mysqli,$db_table_prefix; 
    $stmt = $mysqli->prepare("SELECT 
        id,
        user_name,
        display_name,
        password,
        email,
        activation_token,
        last_activation_request,
        lost_password_request,
        active,
        title,
        sign_up_stamp,
        last_sign_in_stamp,
        dob
        FROM ".$db_table_prefix."users
        WHERE
        $column = ?
        LIMIT 1");
        $stmt->bind_param("s", $data);

    $stmt->execute();
    $stmt->bind_result($id, $user, $display, $password, $email, $token, $activationRequest, $passwordRequest, $active, $title, $signUp, $signIn,$dob);
    while ($stmt->fetch()){
        $row = array('id' => $id, 'user_name' => $user, 'display_name' => $display, 'password' => $password, 'email' => $email, 'activation_token' => $token, 'last_activation_request' => $activationRequest, 'lost_password_request' => $passwordRequest, 'active' => $active, 'title' => $title, 'sign_up_stamp' => $signUp, 'last_sign_in_stamp' => $signIn,'dob'=>$dob);
    }
    $stmt->close();
    return ($row);
}

Hope this helps.

Abhishek Deb
  • 883
  • 1
  • 10
  • 24