I've written this as a tutorial, in sections. Thats to try and make it easier to follow!
It's written to adda field for member no as that is the one which was requested but i've put the bits that need altering in red so it can easily be altered for different purposes of an extra field.
In the example the following is used:
FIELD-Name: member_no
FIELD-Size: around 10
This first bit does the following:
- Adds a new field to your database.
- Alters the registration screen and the editing profile screen to include the new field.
[edit]
THIS MOD IS RELEASED AS A REAL NAMES MOD. SEE http://www.phpbb.com/phpBB/viewtopic.php?t=15421
I HAVEN'T DELETED THE CODE BECAUSE IT EASILY SHOWS WHAT NEEDS TO BE CHANGED FOR OTHER FIELDS (IN RED)
[/edit]
#
#-----[ ACTION ]------------------------------------------
#
# You will need to add one new field into your users table in your SQL database.
SQL-query:
ALTER TABLE users ADD user_member_no VARCHAR (10)
## The member_no needs to be changed to the whatever you want to call the field.
##
## The (10) Specifies the field size so if you want 50 characters then
## change it to (50).
##
## If you have a table prefix then put it before users
## eg if default prefix then the above becomes:
## ALTER TABLE phpbb_users ADD user_member_no VARCHAR (50)
##
#
#----- [ OPEN ] -------------------------------------
# This first section modifies registration and profile to input
# the member number (or whatever the field is for)
phpBB2/includes/usercp_register.php
#
#----- [ FIND ] -------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . "
SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
#
#----- [ REPLACE WITH ] -------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . "
SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . ", user_member_no = '" . str_replace("\'", "''", $member_no) . "'
#
#----- [ FIND ] -------------------------------------
#
$sql = "INSERT INTO " . USERS_TABLE . " (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popuppm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, ";
#
#----- [ REPLACE WITH ] -------------------------------------
#
$sql = "INSERT INTO " . USERS_TABLE . " (user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_member_no, user_active, user_actkey)
VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popuppm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, '$member_no', ";
#
#----- [ FIND ] -------------------------------------
#
$username = htmlspecialchars($userdata['username']);
#
#----- [ ADD AFTER ] -------------------------------------
#
$member_no = htmlspecialchars($userdata['user_member_no']);
#
#----- [ FIND ] -------------------------------------
#
display_avatar_gallery($mode, $avatar_category, $user_id, $email, $current_email, $coppa, $username, $email, $icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $viewemail, $notifypm, $popuppm, $notifyreply, $attachsig, $allowhtml, $allowbbcode, $allowsmilies, $allowviewonline, $user_style, $user_lang, $user_timezone, $user_dateformat);
#
#----- [ REPLACE WITH ] -------------------------------------
#
display_avatar_gallery($mode, $avatar_category, $user_id, $email, $current_email, $coppa, $username, $email, $icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $viewemail, $notifypm, $popuppm, $notifyreply, $attachsig, $allowhtml, $allowbbcode, $allowsmilies, $allowviewonline, $user_style, $user_lang, $user_timezone, $user_dateformat, $user_member_no);
#
#----- [ FIND ] -------------------------------------
#
$template->assign_vars(array(
'USERNAME' => $username,
#
#----- [ ADD AFTER ] -------------------------------------
#
'MEMBER_NO' => $member_no,
#
#----- [ FIND ] ----------------------------
#
'L_EMAIL_ADDRESS' => $lang['Email_address'],
#
#----- [ ADD AFTER ] -------------------------------------
#
'L_MEMBER_NO' => $lang['member_no'],
#
#----- END OF CHANGES TO usercp_register -------------------------------------
#
#
#----- We now need to change the language file -------------------------------------
#
#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every language you support
# It needs translating!!!
phpBB2/language/lang_english/lang_main.php
#
#-----[ FIND ]------------------------------------------
#
//
// Errors (not related to a
// specific failure on a page)
//
$lang['Information'] = "Information";
$lang['Critical_Information'] = "Critical Information";
#
#-----[ ADD, BEFORE ]------------------------------------------
#
//
// Language variables for the new field in user profile
//
$lang['member_no'] = "Member No";
#
#----- Now we need to edit the profile template file so users can add it to their profile ----
#
#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support
phpBB2/templates/subSilver/profile_add_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<tr>
<td class="row1"><span class="gen">{L_WEBSITE}:</span></td>
<td class="row2">
<input type="text" class="post"style="width: 200px" name="website" size="25" maxlength="255" value="{WEBSITE}" />
</td>
</tr>
#
#-----[ AFTER, ADD ]------------------------------------------
#
# Note: you want the 10 in maxlength="10" to be the same as the
# field size you specified when adding field to the database!
#
<tr>
<td class="row1"><span class="gen">{L_MEMBER_NO}: </span></td>
<td class="row2">
<input type="text" class="post"style="width: 200px" name="member_no" size="10" maxlength="10" value="{MEMBER_NO}" />
</td>
</tr>
#
#---------- OK, Users can now register with a member no and ---------------
#---------- edit profile to change their member no ------------------------
#
Now we need to view the member number (or whatever the field is) in a variety of places
The first one of these is in the users profile.
#
#--------- Now we need to view the member number (or whatever the field is) in a variety of places
#
#
#-----[ OPEN ]------------------------------------------
#
# This adds the member no ( or whatever the field is) into the users profile
#
phpBB2/includes/usercp_viewprofile.php
#
#-----[ FIND ]------------------------------------------
#
'INTERESTS' => ( $profiledata['user_interests'] ) ? $profiledata['user_interests'] : ' ',
#
#-----[ ADD AFTER ]------------------------------------------
#
'MEMBER_NO' => ( $member_no ) ? $member_no : ' ',
#
#-----[ FIND ]------------------------------------------
#
//
// Generate page
//
#
#-----[ BEFORE, ADD ]------------------------------------------
#
$member_no = $profiledata['user_member_no'];
#
#-----[ FIND ]------------------------------------------
#
'L_INTERESTS' => $lang['Interests'],
#
#-----[ ADD AFTER ]------------------------------------------
#
'L_MEMBER_NO' => $lang['member_no'],
#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support
phpBB2/templates/subSilver/profile_view_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{L_JOINED}: </span></td>
#
#-----[ BEFORE, ADD ]----------------------------------------
#
<tr>
<td valign="middle" align="right" nowrap="nowrap"><span class="gen">{L_MEMBER_NO}: </span></td>
<td><b><span class="gen">{MEMBER_NO}</span></b></td>
</tr>
#
#------ Now the member no (or whatever the field is) can be seen in the users profile
#
The next place to view it is in the posts (in info under the avatar)
#
#-----[ OPEN ]------------------------------------------
#
# This inserts real names into the posts
phpBB2/viewtopic.php
#
#-----[ FIND ]------------------------------------------
#
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
#
#-----[ REPLACE WITH ]------------------------------------------
#
$sql = "SELECT u.username, u.user_id, u.user_posts, u.user_from, u.user_member_no, u.user_website, u.user_email, u.user_icq, u.user_aim, u.user_yim, u.user_regdate, u.user_msnm, u.user_viewemail, u.user_rank, u.user_sig, u.user_sig_bbcode_uid, u.user_avatar, u.user_avatar_type, u.user_allowavatar, u.user_allowsmile, p.*, pt.post_text, pt.post_subject, pt.bbcode_uid
#
#-----[ FIND ]------------------------------------------
#
$poster = ( $poster_id == ANONYMOUS ) ? $lang['Guest'] : $postrow[$i]['username'];
#
#-----[ AFTER ADD ]------------------------------------------
#
#-------For real name only to be viewed by admins-------
#
$poster_member_no = ( $userdata['user_level'] == ADMIN ) && ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';
#
#-----[ OR ]------------------------------------------
#
#-------If you want the real name to be publically viewable-------
#
$poster_member_no = ( $postrow[$i]['user_member_no'] && $postrow[$i]['user_id'] != ANONYMOUS ) ? $lang['member_no'] . ': ' . $postrow[$i]['user_member_no'] : '';
#
#-----[ FIND ]------------------------------------------
#
'POSTER_NAME' => $poster,
#
#-----[ AFTER ADD ]------------------------------------------
#
'POSTER_MEMBER_NO' => $poster_member_no,
#
#------ Now the member no (or whatever the field is) can be seen in the posts (under their avatar)
#
#
#-----[ OPEN ]------------------------------------------
#
# Remember to do this for every template you support
phpBB2/templates/subSilver/viewtopic_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>
#
#-----[ REPLACE WITH ]------------------------------------------
#
<td width="150" align="left" valign="top" class="{postrow.ROW_CLASS}"><span class="name"><a name="{postrow.U_POST_ID}"></a><b>{postrow.POSTER_NAME}</b></span><br /><span class="postdetails">{postrow.POSTER_RANK}<br />{postrow.RANK_IMAGE}{postrow.POSTER_AVATAR}<br /><br />{postrow.POSTER_JOINED}<br />{postrow.POSTER_MEMBER_NO}<br />{postrow.POSTER_POSTS}<br />{postrow.POSTER_FROM}</span><br /></td>
#
#------ Now the member no (or whatever the field is) can be seen in the posts
#
[edit] THE BIT IN BLUE IS CHANGES FROM EARLIER CODE[/edit]
If anyone wants the field viewed in other placess (such as the memberlist then let me know.