Skip to main content
Topic: Error message "Undefined variable: key" for the Profile.subs.php (Read 530 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Error message "Undefined variable: key" for the Profile.subs.php

Hi,
When I try to access a user's profile, the message "Undefined variable: key" now appears. What's wrong there?
This is displayed in the error log:

Type of error: Undefined
Notice: Undefined variable: key
https://forum.xxx.de/index.php?action=profile

File: /www/htdocs/xxx/xxx/sources/subs/Profile.subs.php
Line: 293

Code: [Select]
291		if (in_array($row['field_type'], array('radio', 'select')))
292 {
293 $replacements['{KEY}'] = $row['col_name'] . '_' . $key;
294 }
295 $output_html = strtr($row['enclose'], $replacements);


Maybe the error has to do with this error message for the addon "Stop Spammer":

Type of error: Undefined
Notice: Undefined index: stopspammer_profilecheck
https://forum.xxx.de/index.php?action=profile

File: /www/htdocs/xxx/xxx/sources/addons/StopSpammer/StopSpammer_hooks.php
Line: 465

Code: [Select]
457	   // Add "Check this member" under "Action" menu in individual profile view
458    public static function profile_areas(&$profile_areas)
459    {
460    global $txt, $scripturl, $memID, $modSettings;
461    loadLanguage('StopSpammer');
462
463    $profile_areas['profile_action']['areas'] = elk_array_insert($profile_areas['profile_action']['areas'], 'activateaccount', array(
464       'checkmember' => array(
465      'label' => $txt['stopspammer_profilecheck'],
466    'custom_url' => $scripturl . '?action=admin;area=viewmembers;sa=query;params=' . base64_encode(serialize(array('mem_id' => $memID, 'types' => array('mem_id' => '=')))),
467    'enabled' => !empty($modSettings['stopspammer_enable']),
468    'sc' => 'get',
469    'permission' => array(
470    'own' => array('profile_remove_any', 'profile_remove_own'),
471    'any' => array('profile_remove_any', 'moderate_forum'),
472    ),
473    )), 'after');
474    }
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #1
Are you running php8 by chance? I get the same error in 8, but not 7.4

 

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #2
Yes, three days ago I switched from PHP 7.4 to 8.0 ...
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0


Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #4
However, I believe that the error was already there before the change to PHP 8.0. Unfortunately, I deleted all error messages before that, so now I can't track when it was first reported.
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #5
Looks like a small bug in the custom profile fields area, probably pretty old as well.  PHP8 is less forgiving which is a good thing really.

I'm not at a place where I can do any testing, but you can try the following to prevent the warning.
Code: (find) [Select]
			{ 
$replacements['{KEY}'] = $row['col_name'] . '_' . $key;
}
with
Code: (replace) [Select]
			{
$key = $key ?? 0;
$replacements['{KEY}'] = $row['col_name'] . '_' . $key;
}
Be safe, Be kind, Happy Programing

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #6
The error message no longer appears, maybe it helped.
However, I still can't view members' profiles, not even my own. And now I can't get into my user account to change anything there either.
Furthermore, the Stop Spammer error mentioned in the start post is still displayed in the error messages. Another one appears when I click on "Members" or "Show Members" in the Admin Center. This is reported then:

Type of error: Undefined
Warning: Undefined array key "stopspammer_count"
https://forum.xxx.de/index.php?action=admin;area=viewmembers;DB9BDCAT42wv=....

File: /www/htdocs/xxx/xxx/sources/addons/StopSpammer/StopSpammer_hooks.php
Line: 390

Code: [Select]
386	$add = array( !$modSettings['stopspammer_enable'] ? '' :
387 array(
388 'position' => 'below_table_data',
389 'value' => '
390 <div style="text-align: center">' . $modSettings['stopspammer_count'] . ' ' . $txt['stopspammer_count'] . '</div>',
391 'class' => 'titlebg',
392 ),


ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #7
I'd suggest disabling that addon and see what errors you are getting.  I'm not familiar with that addon so I don't know if there is a problem with it and php8 or some other issue.
Be safe, Be kind, Happy Programing

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #8
I have thought of that too. I will test it later today.
Is Stop Spammer still good for spam defence at all? This addon was last updated 4 or 5 years ago. The same goes for StopForumSpam. Both authors don't seem to be active in the forum since then either.
Is there a better alternative to these addons?
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #9
Disabling Stop Spammer didn't help. The messages Undefined array key "stopspammer_profilecheck" and Undefined array key "stopspammer_count" still appear.

Do you think I should continue posting in the Addons board in the "Stop Spammer" topic because of the errors?
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #10
I'm not at all familiar with the addon, so I can't comment on its effectiveness. 

If you have disabled the addon, and are still getting errors about it, then that means its still somehow active?  Did you disable or remove the addon?
Be safe, Be kind, Happy Programing

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #11
First it was only deactivated, now I have deleted it completely including links to somewhere in the forum.
The old error messages seem to have disappeared, but I still can't display any profiles and in addition I now can't open any threads or single posts... :o
This database error is now reported for everything:

Type of error: database
Database error: Unknown column 'mem.is_spammer' in 'field list'

https://forum.xxx.de/index.php?action=profile;u=1
https://forum.xxx.de/index.php?topic=472.msg7215
https://forum.xxx.de/index.php?topic=456.0

File: /www/htdocs/xxx/xxx/sources/Load.php
Line: 1005

Code: [Select]
998		// Load the member's data.
999 $request = $db->query('', '
1000 SELECT' . $select_columns . '
1001 FROM {db_prefix}members AS mem' . $select_tables . '
1002 WHERE mem.' . ($is_name ? 'member_name' : 'id_member') . (count($users) == 1 ? ' = {' . ($is_name ? 'string' : 'int') . ':users}' : ' IN ({' . ($is_name ? 'array_string' : 'array_int') . ':users})'),
1003 array(
1004 'blank_string' => '',
1005 'users' => count($users) == 1 ? current($users) : $users,
1006 )
1007 );
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #12
That basically means the "hooks" were not removed during uninstall. 

You should be able to delete the StopSpammer.integration.php file from your sources directory.  The hooks (in this case) are stored in the db and ideally should be removed at some point.
Be safe, Be kind, Happy Programing

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #13
I deleted it there and now everything is OK again. Everything is displayed normally. I clicked around wildly in the forum and nothing triggered an error message. Perfect!
Thanks a lot for your help, Spuds! :)
ElkArte version: 1.1.8 / Theme: BeSocial / PHP 8.0

Re: Error message "Undefined variable: key" for the Profile.subs.php

Reply #14
Which Stop Spammer Integration was this? As in was it mine 😂