Welcome to Geeklog Saturday, June 25 2022 @ 09:13 am EDT

Geeklog Forums

Show username in staticpages


Grant

Anonymous
I need to show the username and users e-mail in staticpages. How do I do this. The staticpage is 'member only'. I recon its something like this:

PHP Formatted Code

return 'hello $user, your email is $email';

 


Thanks in advance.
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/02
Posts: 13073
Location:Stuttgart, Germany
The name of the current user is available through the $_USER array:
PHP Formatted Code
return "Hello, {$_USER['username']}!";
 
It's empty for anonymous users, though.

The email address is not stored in $_USER. You would have to get it from the database.

bye, Dirk
 Quote

Grant

Anonymous
Thanks.

How would I get the e-mail though? I'm not really familiar with fetching MySQL information.. Eek!
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/02
Posts: 13073
Location:Stuttgart, Germany
Quote by Grant: How would I get the e-mail though?

Something like
PHP Formatted Code
$email = DB_getItem ($_TABLES['users'], 'email', "uid = {$_USER['uid']}");
 
would return the email address of the current user (again, that won't work for anonymous users).

bye, Dirk
 Quote

Grant

Anonymous
Quote by Dirk:
PHP Formatted Code
$email = DB_getItem ($_TABLES['users'], 'email', "uid = {$_USER['uid']}");

 

bye, Dirk


If i put that in, and enter.. lets say

PHP Formatted Code

return 'your email is £email';

 


its doesnt do anything but print 'your email is $email' on the page... more help please Wink
 Quote

Status: offline

inspiremin

Forum User
Regular Poster
Registered: 07/01/04
Posts: 111
Think in terms of US Dollars "$" not "£"
www.Scripturetoolkit.com www.inSPIREministries.com
 Quote

Status: offline

Dirk

Site Admin
Admin
Registered: 12/01/02
Posts: 13073
Location:Stuttgart, Germany
Assuming the Pound symbol was a typo: You have to enclose the string in double quotes, not single quotes.

bye, Dirk
 Quote

Grant

Anonymous
Thanks. Your assumtion was correct, it was a typo Wink It works now! Silly mistake...
 Quote

All times are EDT. The time is now 09:13 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content