PDA

View Full Version : How to set a profilefield via PHP Code


stefan1994
07-02-2011, 11:39 AM
Hello,

can someone tell me how i can set a profilefield of a user within my PHP Code?

At the moment I am using this code:
if ($_REQUEST['do'] == 'update')
{
$vbulletin->input->clean_array_gpc('p', array(
'username' => TYPE_STR,
'password' => TYPE_STR
));

// init user data manager
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_STANDARD);
$userdata->set_existing($vbulletin->userinfo);

// profile stuff
$userdata->set('field5', $vbulletin->GPC['username']);
$userdata->set('field6', $vbulletin->GPC['password']);

// save the data
$userdata->save();

if ($vbulletin->session->vars['profileupdate'])
{
$vbulletin->session->set('profileupdate', 0);
}

$vbulletin->url = 'rodcust.php?' . $vbulletin->session->vars['sessionurl'] . 'do=overview';
eval(print_standard_redirect('redirect_updatethank s', true, true));
}

But this outputs errors:

Schwerer Fehler: Field field5 is not defined in $validfields in class vB_DataManager_User in [path]\includes\class_dm.php (Zeile 515)


After some time of search i found this:

// set the valid fields
$userdata->validfields['field5'] = array(TYPE_STR, REQ_YES);
$userdata->validfields['field6'] = array(TYPE_STR, REQ_YES);


and added it after before "// profile stuff". It ended up in this:
Datenbankfehler in vBulletin 4.1.4:

Invalid SQL:
UPDATE user SET
field5 = 'test',
field6 = 'test'
WHERE userid = 1;

MySQL-Fehler : Unknown column 'field5' in 'field list'
Fehler-Nr. : 1054
Fehler-Zeit : Saturday, 02.07.2011 @ 11:32:51
Datum : Saturday, 02.07.2011 @ 11:32:51
Skript : http://domain.tld/page.php?do=update
Referrer : http://domain.tld/page.php
IP-Adresse : 255.255.255.255
Benutzername : user
Klassenname : vB_Database
MySQL-Version : 5.1.53-community-log

So please can someone tell me how i can set the profilefields "field5" and "field6" within my PHP code?

vbresults
07-02-2011, 12:55 PM
<a href="http://members.vbulletin.com/api/vBulletin/vB_DataManager_User.html#set_userfields" target="_blank">http://members.vbulletin.com/api/vBu...set_userfields</a>

kh99
07-02-2011, 01:09 PM
So please can someone tell me how i can set the profilefields "field5" and "field6" within my PHP code?

You want to do something like this:


$fields = array('field5' => $vbulletin->GPC['username'],
'field6' => $vbulletin->GPC['password']);
$userdata->set_userfields($fields);



You don't need to set the validfields.

stefan1994
07-02-2011, 04:16 PM
Thank you, works as expected.