Raised This Month: $32 Target: $400
 8% 

Make nick change in mySQL work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-08-2018 , 10:26   Make nick change in mySQL work
Reply With Quote #1

So i have a plugin and it sends data to mySQL.
But i would like the plugin to update the nickname if i change it.
If my nickname ingame is Player 1 and i change it to Player 2 then mySQL doesnt update to the new nickname.

Can someone check these parts of the code and see if it has some errors or something?


Here are parts from the plugin which i think should change the nickname in mySQL but it doesnt.
PHP Code:
new Team[33], OldName[33][32
PHP Code:
public client_infochanged(id

    new 
newname[32],oldname[32
    
get_user_info(id"name"newname,31
    
get_user_name(idoldname31
    
    if(!
equali(newnameoldname))
    {
        
OldName[id] = oldname;
        
MySQL_UpdateName(id);
        return 
PLUGIN_HANDLED;
    }
    return 
PLUGIN_CONTINUE;

PHP Code:
public MySQL_UpdateName(id) {
    
replace_all(OldName[id], 32"'""\'"); 
    
replace_all(OldName[id], 32"^"", "\^""); 

    
formatexMySQL_QuerycharsmaxMySQL_Query ), "UPDATE `online_players` SET `username` = '%s' WHERE `username` = '%s'"get_user_name_ex(id), OldName[id] ) 
    
SQL_ThreadQuery(MySQL_Tuple"SQL_TrashHandler"MySQL_Query);   

PHP Code:
stock get_user_name_ex(id

    new 
szName[33]; 
    
get_user_name(idszNamecharsmax(szName)); 

    
replace_all(szNamecharsmax(szName), "'""\'"); 
    
replace_all(szNamecharsmax(szName), "^"", "\^""); 

    return 
szName


Last edited by 4ever16; 06-08-2018 at 10:28.
4ever16 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-08-2018 , 13:26   Re: Make nick change in mySQL work
Reply With Quote #2

Poorly coded...

Code:
const MAXPLAYERS = 32; new g_szOldName[MAXPLAYERS+1][32];

Code:
public client_infochanged(pPlayer)  {     new szName[32];     get_user_name(pPlayer, szName, charsmax(szName));     if(!equali(szName, g_szOldName[pPlayer]))     {         formatex(g_szOldName[pPlayer], charsmax(g_szOldName[]), "%s", szName);         MySQL_UpdateName(pPlayer);     } } MySQL_UpdateName(pPlayer) {     new szQuery[32], szName[32];     get_user_name(pPlayer, szName, charsmax(szName));     replace_all(g_szOldName[pPlayer], charsmax(g_szOldName[]), "'", "\'");     replace_all(g_szOldName[pPlayer], charsmax(g_szOldName[]), "^"", "\^"");     replace_all(szName, charsmax(szName), "'", "\'");     replace_all(szName, charsmax(szName), "^"", "\^"");     formatex(szQuery, charsmax(szQuery), "UPDATE `online_players` SET `username` = '%s' WHERE `username` = '%s'", szName, g_szOldName[pPlayer]);     SQL_ThreadQuery(MySQL_Tuple, "SQL_TrashHandler", szQuery); }
__________________









Last edited by CrazY.; 06-08-2018 at 16:35.
CrazY. is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-08-2018 , 15:05   Re: Make nick change in mySQL work
Reply With Quote #3

Compile error.
4ever16 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-08-2018 , 16:35   Re: Make nick change in mySQL work
Reply With Quote #4

Updated.
__________________








CrazY. is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-08-2018 , 18:13   Re: Make nick change in mySQL work
Reply With Quote #5

Why not only update name on client disconnect?
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-08-2018 , 18:48   Re: Make nick change in mySQL work
Reply With Quote #6

Compiling worked fine this time but it didnt update the nickname in the database.
When i changed my nickname it still shouwed the old nickname inthe database.
4ever16 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-09-2018 , 08:24   Re: Make nick change in mySQL work
Reply With Quote #7

Quote:
Originally Posted by ^SmileY View Post
Why not only update name on client disconnect?
I used the code given by @4ever16 as an base, but can be any way.

Quote:
Originally Posted by 4ever16 View Post
Compiling worked fine this time but it didnt update the nickname in the database.
When i changed my nickname it still shouwed the old nickname inthe database.
So something it's wrong with your tuple or connection.
__________________








CrazY. is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-09-2018 , 08:39   Re: Make nick change in mySQL work
Reply With Quote #8

Turple?
Connection no... Cause it writes my old name to database if im in the server but when i change my name it doesnt update.
4ever16 is offline
4ever16
Veteran Member
Join Date: Apr 2015
Old 06-12-2018 , 06:44   Re: Make nick change in mySQL work
Reply With Quote #9

Bump!
4ever16 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode