I have a user profile (using the core Profile module), and after I made some changes and submitted the form to update my profile, I got this:

Fatal error: Cannot access empty property in /sites/all/modules/spam/modules/spam_user.inc on line 226

Comments

ebeyrent’s picture

This fixes the issue:


$result = db_query('SELECT fid, value FROM {profile_values} WHERE uid = %d', $user->uid);
while ($value = db_fetch_object($result)) {
  $name = db_result(db_query('SELECT name FROM {profile_fields} WHERE fid = %d', $value->fid));
  if($value->value) {
    $user->$name = $value->value;
  }
}

ron_s’s picture

I wasn't able to get this to work using the code above. PHP doesn't like the "$user->$name" nomenclature in PHP 5.2.14. So instead I was able to get it to work like this, using a defined variable and the name of the variable in curly brackets:

<?php
$result = db_query('SELECT fid, value FROM {profile_values} WHERE uid = %d', $user->uid);
while ($value = db_fetch_object($result)) {
  $name = db_result(db_query('SELECT name FROM {profile_fields} WHERE fid = %d', $value->fid));
  if($value->value) {
    define(FIELD_NAME, $name);
    $user->{FIELD_NAME} = $value->value;
  }
}
?>
gnassar’s picture

The 5.x branch is no longer supported, as of a year or so back.

You probably want to use the 5.x-3.x-dev build if you're still using 5.x.

If you come up with a clean, simple patch for it that doesn't take much double-checking or support, it is also possible that one of us may be willing to commit it to that branch.

gnassar’s picture

Status: Active » Closed (won't fix)