PDA

View Full Version : Change username on custom php page.


Shalom.
07-08-2014, 07:38 PM
hello, i just make a new php page that allowed users to change their usernames.
i use this code:
$db->query_read("UPDATE user SET username='$newusername' where userid=$userid");
but it's sucks because in the fromdisplay i still see the old username.
i tried to find the code that used on the admincp but i didn't find it..
please help, thanks.

ForceHSS
07-08-2014, 07:42 PM
<a href="https://vborg.vbsupport.ru/showthread.php?t=236980&highlight=change+username" target="_blank">https://vborg.vbsupport.ru/showt...hange+username</a>

Shalom.
07-08-2014, 07:45 PM
i have a custom page..
i just want the code to set the new username.
i try this code:
$db->query_read("UPDATE user SET username='$newusername' where userid=$userid");
but in the forumdisply i still have the old username

(i tried to find the code from the admincp>user.php but i didn't find the code..

ForceHSS
07-08-2014, 07:50 PM
the above plugin will do it for you

Shalom.
07-08-2014, 07:51 PM
i dont want plugin..
i have the all code, i just want code to update the username in all tables(on db)

ForceHSS
07-08-2014, 07:53 PM
Then why don't you download that plugin and see how it works

Shalom.
07-08-2014, 07:55 PM
i did..
$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_CP);
$userdata->set_existing(fetch_userinfo($exists['userid']));
$userdata->set('username', $vbulletin->GPC['newusername']);
$userdata->save();
unset($userdata);
but it dosent work..
maybe i have mistake ?
can u give me expamle with that code?

Dave
07-08-2014, 07:58 PM
It shows the old username because in the post table there's a column called username and in the thread table there are 2 columns called postusername and lastposter.

Shalom.
07-08-2014, 08:00 PM
It shows the old username because in the post table there's a column called username and in the thread table there are 2 columns called postusername and lastposter.
so how in the admincp it's change the all username in all tables?
can u give me the code from the admincp ? i can't find it :(

tbworld
07-08-2014, 08:05 PM
hello, i just make a new php page that allowed users to change their usernames.
i use this code:
$db->query_read("UPDATE user SET username='$newusername' where userid=$userid");
but it's sucks because in the fromdisplay i still see the old username.
i tried to find the code that used on the admincp but i didn't find it..
please help, thanks.

First, it would have been nice if you showed your code, when your asking for assistance time.
Second, where is your query_write?
Third, use the datamanager you will have less problems. See "/includes/class_dm_user.php". There are several examples here on the board on how to use the datamanagers. I will see if I can find you a reference.

:)

Dave
07-08-2014, 08:07 PM
https://members.vbulletin.com/api/vBulletin/vB_DataManager_User.html#update_username

There you go. :)

Shalom.
07-08-2014, 08:07 PM
First, it would have been nice if you showed your code, when your asking for assistance time.
Second, where is your query_write?
Third, use the datamanager you will have less problems. See "class_user_dm.php". There are several examples here on the board on how to use the datamanagers. I will see if I can find you a reference.

:)
1.i can send u the code on pm..
2.i cant find this file..
3.please give me one.

tbworld
07-08-2014, 08:09 PM
Update: I see in post #6, #8, this was already covered. I was on the phone so long my post is barely relevant anymore. :)

Shalom.
07-08-2014, 08:12 PM
https://members.vbulletin.com/api/vBulletin/vB_DataManager_User.html#update_username

There you go. :)

update_username (integer $userid, [string $username = null])
>
update_username ($userid, $newusername)

its good ?

tbworld
07-08-2014, 08:14 PM
Send or post your code, and you have already started to use the datamanager. That is the approach you should be taking.

Dave
07-08-2014, 08:14 PM
update_username (integer $userid, [string $username = null])
>
update_username ($userid, $newusername)

its good ?

Exactly.
Now integrate it with the piece of code you posted earlier which uses the datamanager.

Shalom.
07-08-2014, 08:25 PM
Exactly.
Now integrate it with the piece of code you posted earlier which uses the datamanager.
sry, but i dont understand u :(

mokujin
07-08-2014, 08:48 PM
Run this query in phpmyadmin, hope it helps:

UPDATE post SET username = 'New User Name Here' WHERE userid = $userid

tbworld
07-08-2014, 09:18 PM
This should work:


global $vbulletin;

// error processing for the datamanager if needed.
require_once "d:/servers/z421/web/bbs/includes/adminfunctions.php";

// Existing User
$userid = 6; // Existing User ID
$newusername = 'david1'; // New user name string (cleaned)

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_CP);
$userinfo = fetch_userinfo($userid);
$userdata->set_existing($userinfo);
$userdata->set('username', $newusername);
$userdata->save();
unset($userdata);
I ran a quick test. :)

Looking at what you were doing, I am guessing you can take it from here.

Shalom.
07-08-2014, 10:05 PM
This should work:


global $vbulletin;

// error processing for the datamanager if needed.
require_once "d:/servers/z421/web/bbs/includes/adminfunctions.php";

// Existing User
$userid = 6; // Existing User ID
$newusername = 'david1'; // New user name string (cleaned)

$userdata =& datamanager_init('User', $vbulletin, ERRTYPE_CP);
$userinfo = fetch_userinfo($userid);
$userdata->set_existing($userinfo);
$userdata->set('username', $newusername);
$userdata->save();
unset($userdata);
I ran a quick test. :)

Looking at what you were doing, I am guessing you can take it from here.
thanks, it work's !

tbworld
07-08-2014, 10:09 PM
Glad to hear :)

Please, thank all the other gracious volunteers in your thread that gave you a hand, they don't ask for much. Personally, I prefer a beer.:)

Shalom.
07-08-2014, 10:17 PM
thanks all, have a good night <3