Sublime directory Surf the web anonymous Pagerank Monitor


adding new field to user table

RealEstateAdvertis
Tue 6 February 2007, 06:28 am GMT +0100
I needed to add a new field to the user table that basically receives an affiliate ID number from a url variable. I've made a series of changes to access_user_class.php and to the register.php page as documented below. It seems to work without problem but I'm sure it can be dressed up but I thought I would pass on what I have done. The new value from the url variable is being inserted the databse at the registration. 

Here are the changes I made.

I added a column to the table users (I happened to name it "upline_num" and it is in the sql statement below) and inserted a variable named "showcookie2" that I retrieve from the url.
The line numbers are approximate as they change when lines are added.

On access_user_class.php
I added

var $user_showcookie2; at line 79

Change line 638 (added $showcookie2 like this:

function register_user($showcookie2,$first_login, $first_password, $confirm_password, $first_name, $first_info, $first_email) {

Change line 659 (added db column name upline_num) like this:
$sql = sprintf("INSERT INTO %s (id, upline_num, login, pw, real_name, extra_info, email, access_level, active) VALUES (NULL, %s, %s, %s, %s, %s, %s, %d, 'n')",
(note that I also added another %s after values above to match the added parameter "upline_num")

Added line 662
$this->ins_string($showcookie2),

Then in register.php

I collect the showcookie2 value from the cookie  and
changed the line 22 (i.e. I added $_POST['showcookie2'],) like this
$new_member->register_user($_POST['showcookie2'],$_POST['login'], $_POST['password'], $_POST['confirm'], $_POST['name'], $_POST['info'], $_POST['email']); // the register method

hope it helps!



olaf
Tue 6 February 2007, 07:10 am GMT +0100
I don't suggest to add fields to the user table, use the profile table for additional information.

another way is to use the field extrainfo...

Archive for SMF v1.00 by N.P. Valid XHTML 1.0 Transitional