PDA

View Full Version : Registration fields INSERT into another dbase also?


Jim Nayzium
03-18-2007, 02:01 PM
I would like for my custom fields that I have added through the admin cp to INSERT into my custom database upon registration.

I have successfully hacked into the register.php and the functions_login.php to get it all to work on the 'pre-defined' fields...but the custom fields seems to have an array code that is over my head.

Basically, I have only added firstname and lastname fields, and I have another table in my database that is customized to use for my classifieds section, which is running a different custom software.

I am able to INSERT the username and password just fine tapping into the vBullein->userinfo stuff...and the GPC array.

However, my problem is it seems like the custom stuff is all inserted into one array and then that full array is inserted into the vb_ table all at once...

I know how to summon on row of an array using array['desiredinfo'] syntax...

but what if the desiredinfo is an array ??

seems like I want something like

array['desiredinfoArray']['desired_info_inside_this_array']

OR alternatively -- can someone just give me the best way to have the registration custom added fields be INSERTed into the vb database, AND into another database upon registration....

thanks.

Flexserve
03-20-2007, 01:07 AM
I need to know this also. No one on forums seems to know how, it's been asked several times.:confused:

Jim Nayzium
03-20-2007, 01:29 AM
Well, I just finally solved this on my own.

I am so used to the phpBB open source world where every user is so helpful and everyone works so well together....

the catch is they NEED to be, cuz the software requires all that help...hahaha.

I love this vBulletin deal --- MUCHO....

$vbulletin->GPC['userfield']["field5"]
$vbulletin->GPC['userfield']["field6"]

are the values you need to insert for your custom fields...assuming these are the first two cusstom fields you added....

for me it was 5 -= first name and 6 =- last name

and I inserted them into another database table upon regisration....so they hit userfield5 and 6 in the vb_userfield tables....or usertext not sure which....

and they also hit my database table


$insertSQL = sprintf("INSERT INTO table_name (firstname, lastname) VALUES (%s, %s)",
GetSQLValueString($vbulletin->GPC['userfield']["field5"], "text"),
GetSQLValueString($vbulletin->GPC['userfield']["field6"], "text"));

Of course GetSQLValueString is a dreamweaver code inserted when you insert your recordset to begin with...

Flexserve
03-20-2007, 04:53 PM
Can you explain where to put this??

Sorry, new to vbulletin ways of doing things and this is something I need to do asap.

Thanks in advance:D

Jim Nayzium
03-20-2007, 06:56 PM
register.php starting around line 307


$class = mysql_pconnect('IP_ADDRESS_DBASE_HERE', 'DBASE_USER>HERE', 'DBASE_Password_HERE') or trigger_error(mysql_error(),E_USER_ERROR);

//This is auto-created by DREAMWEAVER when you do a recordset.
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
//Here is the good part....
$insertSQL = sprintf("INSERT INTO class_users (username, password, email, firstname, lastname) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($vbulletin->GPC['username'], "text"),
GetSQLValueString($vbulletin->GPC['password_md5'], "text"),
GetSQLValueString($vbulletin->GPC['email'], "text"),
GetSQLValueString($vbulletin->GPC['userfield']["field5"], "text"),
GetSQLValueString($vbulletin->GPC['userfield']["field6"], "text"));
mysql_select_db('DBASE-NAME-HERE-AGAIN', $class);
$Result1 = mysql_query($insertSQL, $class) or die(mysql_error());





My $class file is obviously my connection to my database....
Hope you understand the sprintf php command - if not do a google for sprintf and php....

MarkPW
03-20-2007, 07:13 PM
There is no need to modify vbulletin's files to achieve this. vB have a hook system of which allows you to execute external code at many different locations within vB's files, such as the registration or activation process.

See: What is a hook? (http://www.vbulletin.com/docs/html/main/what_is_hook)

With regard to adding custom fields to a seperate db table upon registration - all you need to do is add a plug-in at the correct hook location (via the AdminCP), and include the code you wish to run. In this instance, you would add a hook at the following location: "register_addmember_complete" and include the database code you wish to run.

Similarly, if you only want to copy user details upon activation, you would use the hook, "register_activate_process".

Hope this helps!

Jim Nayzium
03-20-2007, 07:19 PM
DUDE --- WHERE HAVE YOU BEEN!!!! This is great information....I am so used to OSCommerce and phpBB -- just hacking away at the actual code ---

MarkPW's way sounds much much better!!!

MarkPW
03-20-2007, 07:36 PM
No problem ;)

Jim Nayzium
03-20-2007, 07:47 PM
One more quick one -- this has revolutionized my thinking, but I cannot quite wrap my head around it....

So I go to Add New Plugin---

and insert my custom php code in that box on that screen, and toggle the drop down to the location I want....and that is it??

Do I need to add a product or anything like that?

I am thinking I am going to remove all my customizations from the register.php and the functions_login.php files and put them in hooks so I can upgrade easier...

But I am not quite comprehending the whole process. I think it is so simple, I am just having a hard time believing it.

I attached a pdf screen grab of the page I am talking about.

No chance you could just walk me through a very simple one from start to finish...

something like, add this 123TEXT to this HOOK location and then watch the page refresh and see your text....

REALLY appreciate....

Flexserve
03-20-2007, 08:37 PM
Please do tell..we (a group) are trying to accomplish this very task.

MarkPW
03-20-2007, 11:15 PM
and insert my custom php code in that box on that screen, and toggle the drop down to the location I want....and that is it??

Yes, that's it. When you add a plugin, I recommend you look through the vb files to ensure you have chosen the appropriate (hook) location to execute your code.

Do I need to add a product or anything like that?

No, you can add it to the default (vBulletin).

No chance you could just walk me through a very simple one from start to finish...

I didn't quite interpret what you were asking, but since this topic was about saving info to a seperate table upon registration, I'll show you how to do that.

Basically, you would "Add New Plugin" -> choose "vbulletin" as product -> Select the hook location of either "register_addmember_complete" (to execute your code upon a successful registration), or "register_activate_process" to execute upon a successful e-mail validation (I personally prefer this to keep my seperate table clean of any unvalidated users) -> enter a name for your plugin -> and add your code. Example (using vB's database class):

$db->query("INSERT INTO your_table SET userid='".$userinfo['userid']."'");

Flexserve
03-21-2007, 01:03 AM
Ok, Jim can you please post a final code or the plugin itself..I get "header already sent" errors...hmmm.. Got a friend working on it too.. I'll keep you posted if I find a resolution before someone hopefully solves this riddle.

Jim Nayzium
03-21-2007, 01:34 AM
header already sent errors are becasue you are echoing something you shouldnt...or you have spaces in the acutal non-php code on the page...

I have hacked this all to pieces tonight and is far to complex to 'just post' here...sorry dude...but the last message posted should really work for you...

YOu don't want to have to do what I did...which was check the SESSSION variables and madneess..

mine is awful....

akxt660
10-01-2010, 08:36 PM
I need to add the Location field to the registration form, some idea?