How to display/input custom field data on another page of the website?

Started by Goodman854, June 27, 2016, 06:31:50 PM

Previous topic - Next topic

Goodman854

Hey so what I'm trying to do is have a field or box auto filled (without being modifiable easy), with data assoiated to that user.

On Sign up I used the built in custom profile thing in SMF to ask them a question.
Example "What is your youtube username: joe"

On this page I want the text box to fill with "joe"

I've looked around trying to figure this out but so far have been unable to come up with a result.

The closest suggested thing i found was:
if (empty($context['user']['id']))
  echo 'The current user is a guest';
else
{
  echo 'The current user: id ', $context['user']['id'], ', username ', $context['user']['name'], '<br />';

  $query = $smcFunc['db_query']('', '
    SELECT value
    FROM {db_prefix}themes
    WHERE id_member = {int:member}
      AND variable = {string:variable}',
    array(
      'member' => $context['user']['id'],
      'variable' => 'cust_youtube',
    )
  );

  $row = $smcFunc['db_fetch_assoc']($query);
  $smcFunc['db_free_result']($query);

  echo 'The value of the custom field is ', $row['value'];
}

However it displayed nothing. Am I doing something wrong?

PS: the page displaying this is a SMF - Simple Portal Page.

Related Threads:
http://www.simplemachines.org/community/index.php?topic=379579.0
http://www.simplemachines.org/community/index.php?topic=459286.0

EDIT: Also if a mod is reading this could you please move this to SMF 2.0 Support. Thanks. (if it fits better there)

Grammy

Testing your code in my SP page, it shows simply

"The current user is a guest".

(Did you remember to set the Type pulldown to PHP?  Don't use opening and closing PHP tags, just the content between them.)

Not that I can help with what you want to do, but I just wanted you to know that your code does display a result in the SP page.

:)

Goodman854

Quote from: Grammy on June 27, 2016, 06:45:43 PM
Testing your code in my SP page, it shows simply

"The current user is a guest".

(Did you remember to set the Type pulldown to PHP?  Don't use opening and closing PHP tags, just the content between them.)

Not that I can help with what you want to do, but I just wanted you to know that your code does display a result in the SP page.

:)
that's what it showed on mine too sorry I misspoke with that. That however isn't what I'm looking for it to show.
I want it to say what the user has in that custom profile field like age, or gender.

"'variable' => 'cust_youtube',"
IE: the final line does nothing
"echo 'The value of the custom field is ', $row['value'];"

All I get is the current user is a guest. As well. Which is also odd since the current user isn't a guest.


EDIT: woops read your post to fast you already understood that lol.

Also in regrades to
Quote(Did you remember to set the Type pulldown to PHP?  Don't use opening and closing PHP tags, just the content between them.)
Yes.

Goodman854

Also if a mod is reading this could you please move this to SMF 2.0 Support. Thanks.

Illori

Quote from: Goodman854 on June 29, 2016, 04:19:48 PM
Also if a mod is reading this could you please move this to SMF 2.0 Support. Thanks.

this is a coding question, not a general support question. it is in the correct location for getting the help you need.

Goodman854

Quote from: Illori on June 29, 2016, 04:48:35 PM
Quote from: Goodman854 on June 29, 2016, 04:19:48 PM
Also if a mod is reading this could you please move this to SMF 2.0 Support. Thanks.

this is a coding question, not a general support question. it is in the correct location for getting the help you need.
Ok I wasn't sure.

EDIT:
And I was also semi realizing this board probably gets less attention.  :( Hopefully someone can help!

nend

Not sure how Simple Portal works, but you may need to declare you want the use the global $context.

Just add this to the top.

global $context;

Goodman854

Quote from: nend on June 29, 2016, 09:24:25 PM
Not sure how Simple Portal works, but you may need to declare you want the use the global $context.

Just add this to the top.

global $context;

THANK YOU. That party fixed it.
Now it displays:

The current user: id 1, username myusername

Fatal error: Function name must be a string in /Sources/Subs-Portal.php(1167) : eval()'d code on line 9


You're a godsend for getting this much lol. Any idea whats wrong with the rest of it? Something seems to go wrong when I call for the custom variable.

nend

I missed one, need $smcFunc for the database call.
global $context, $smcFunc;

Goodman854

Quote from: nend on June 30, 2016, 12:56:09 AM
I missed one, need $smcFunc for the database call.
global $context, $smcFunc;
OMG dude thank you so much you have no idea how much this helps. You are a fu**ing king!

I promise to write story's about you. lol.

Seriously though thanks a billion.

Advertisement: