Old 02-23-2008   #1 (permalink)
Registered User
 
Join Date: Feb 2008
Posts: 1

Membership System Customization

First, thank you for the great tutorial. I'm beginning with PHP and it was very easy to run through and understand.

I'm currently trying to customize the member area of the tutorial and I wanted to have a section where it says "Welcome '$username'", where $username is replaced with the username of whoever is logged in. I've been trying a few options but can't seem to find the right approach.

Do I call a mysql_query and get the username from the database? Any help would be much appreciated. Thanks in advance!
jeffkab is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 03-02-2008   #2 (permalink)
Registered User
 
Join Date: Aug 2004
Posts: 110

Easiest way is to create an array for the user.

Create a file that can be included in every page of your site. Or include the below in something like your header include.

The basic principal is you create a cached array to store any info you want to display on the page without needing to query the DB for each instance.

Note, I have not gone through the membership tutorial here so obviously DB field names and values will need to be changed to match your DB.

I choose to set a cookie for the user with their username when they are logged in. I can then call the cookie username value to use in the query. The membership tut here uses a session cookie I believe. Same thing, different storage capabilities.

PHP Code:
if($_SESSION['user'] != '') { //checks for the session cookie first. If it's there proceed.
    
$user $_SESSION['user'];
    
$usr mysql_query("SELECT * FROM users WHERE name = '$user'") or die(mysql_error()); 
    while (
$user mysql_fetch_array($usr)) {
        
$u = array('id' => $user['id'], 'name' => $user['name'], 'email' => $user['mail'], 'fname' => $user['Firstname'], 'lname' => $user['Lastname'], 'address' => $user['addy'], 'city' => $user['city'], 'state' => $user['state'], 'zip' => $user['zip'], 'phone' => $user['phone'], 'pass' => $user['Pword']);
    }
    
mysql_free_result($usr);

With that array set you can then call any user information on the page. Such as $u['name'] will equal the username of the person browsing, $u['city'] will echo their city, etc. Change the array values to match your database.
Jolt is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Membership System Vrocka HTML / PHP / ASP / JS 0 11-13-2007 06:28 AM
FAQ: A Complete Membership System scrowler BioRUST Specific Threads 13 01-18-2007 11:16 PM
A Complete Membership System Tones HTML / PHP / ASP / JS 0 01-14-2007 02:42 PM
RE: A Complete Membership System ThEMakeR HTML / PHP / ASP / JS 0 07-18-2006 12:59 PM


All times are GMT +1. The time now is 09:39 AM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT