Mysql Change Name HElp Pleaasee
#1

Hi Allll
I Use MySql Game Mode And Dont Have Change Name System I need deleted the old account and replaced it with the new one ANyone Can Help Me Pleaaase TnX
Reply
#2

SQL is nothing like file systems that renaming a file requires to delete the current and create a new one. All you have to do is execute a query:
pawn Код:
// an example (in mysql_format):
"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1", new_name, old_name
// or better yet "... WHERE ID=%i LIMIT 1" if you have a unique ID per-player.
Of course, you should check if the name is valid before updating the table.
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
SQL is nothing like file systems that renaming a file requires to delete the current and create a new one. All you have to do is execute a query:
pawn Код:
// an example (in mysql_format):
"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1", new_name, old_name
// or better yet "... WHERE ID=%i LIMIT 1" if you have a unique ID per-player.
Of course, you should check if the name is valid before updating the table.
This Is My Ban System Please GIve Me CHange Name Systeem On /Changename I Realy Need It And I Cant MAke It TNX
Код HTML:
{
	if(!adminLevel(playerid, 4))
		return 0;
			
	new otherID, time, reason[26];
	if(sscanf(params, "uds[26]", otherID, time, reason))
	{
		Usage(playerid, "ban <playerid> <day> <reason>");
	}
	else
	{
		if(time < 1 || time > 30)
		{
			Server(playerid, "Please input between 1 - 30.");
			return 1;
		}
		
		if(isMe(playerid, otherID))
		{
			Server(playerid, "You can't use this command to yourself.");
			return 1;
		}
		
		if(!isConnected(otherID))
		{
			Server(playerid, "That player isn't logged in!");
			return 1;
		}
		
		if(isHigher(playerid, otherID))
		{
			Server(playerid, "You can't use this command to that player.");
			return 1;
		}
		
		time = time * 1440;
		ban(playerid, otherID, reason, time);
	}
	return 1;
}
Reply
#4

You dont need to delete the account. Use the mysql update function.

PHP код:
new query[128], oldname[MAX_PLAYER_NAME], newname[MAX_PLAYER_NAME];
GetPlayerName(playeridoldnamesizeof(oldname));
format(newname,sizeof(newname),"%s",inputtext);//Inputtext for example if you will create a dialog for this
SetPlayerName(playeridnewname);
format(query,sizeof(query),"UPDATE your_account_table_name SET your_name_field_name ='%s' WHERE Name = '%s'",newname,oldname);
mysql_query(query); 
Reply
#5

If inputtext is empty, it will crash the server and you don't escape the strings.

Anyway, it is really simple. Modify the code to match the table's and columns' name as we can't possible guess your code and display a dialog with input style. On its response:
PHP код:
if (response)
{
    if (!
inputtext[0])
    {
        
SendClientMessage(playerid, -1"Error: Input a name.");
        
ShowPlayerDialog(...);
        return 
1;
    }

    new 
p_name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridp_nameMAX_PLAYER_NAME);

    switch (
SetPlayerName(playeridinputtext))
    {
        case 
1:
        {
            new 
Query[100];

            
mysql_format(connection_handle_hereQuerysizeof Query"UPDATE users SET name='%e' WHERE name='%e' LIMIT 1"inputtextp_name);
            
mysql_tquery(connection_handle_hereQuery"""");
            
SendClientMessage(playerid, -1"Name was changed successfully.");
        }
        case 
0SendClientMessage(playerid, -1"Error: Your currently name is the same.");
        case -
1SendClientMessage(playerid, -1"Error: The name cannot be changed (it's already in use, too long or has invalid characters).");
    }
    return 
1;

If you don't know about the dialogs, read: https://sampwiki.blast.hk/wiki/ShowPlayerDialog and https://sampwiki.blast.hk/wiki/OnDialogResponse

And don't expect a working code for just copy-paste, you SHOULD try an attempt yourself.
Reply
#6

Not Work Brother
Reply
#7

|Please Give Me /Changename Command For Mysql Please So TnX
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)