ChangeName MysqL
#1

hi, I made a /changename cmd so if I have a house to change name..but it dosent change the name properly..


PHP код:
forward ChangeName(playeridnewname[]);
public 
ChangeName(playeridnewname[]) {
    if(
cache_get_row_count(playerid))
    {
        return 
SendClientMessage(playerid, -1"This name doesn't exist!");
    }
    new 
current[MAX_PLAYER_NAME];
    
GetPlayerName(playeridcurrentsizeof current);
    new 
query[128];
    
mysql_format(mysql_dbquerysizeof query"UPDATE `players` SET `Name` = '%s' WHERE `Name` = '%s'"newnamecurrent);
    
mysql_tquery(mysql_dbquery);
    
SetPlayerName(playeridnewname);
    return 
1;


PHP код:
dcmd_changename(playeridparams[])
                    {
                        if(
PlayerToPoint(3.0,playerid,358.5789,166.3685,1008.3828))
                        {
                            if(
ChangedName[playerid] == 1) return SendClientMessage(playeridCOLOR_GREY"testt");
                            if(
isnull(params))
                            {
                                return 
SendClientMessage(playerid, -1"/changename [new name]");
                            }
                            if(
strlen(params) > MAX_PLAYER_NAME)
                            {
                                return 
SendClientMessage(playerid, -1"Name has to have 24 caracters.");
                            }
                            new 
current[MAX_PLAYER_NAME];
                            
GetPlayerName(playeridcurrentsizeof current);
                            if(!
strcmp(currentparamsfalse))
                            {
                                return 
SendClientMessage(playerid, -1"This is already your name!");
                            }
                            new 
housekey PlayerInfo[playerid][pPhousekey];
                            if(
PlayerInfo[playerid][pPhousekey] != 255)
                            {
                                new 
query[100];
                                
format(querysizeof(query), "UPDATE houseid SET Owner='%s' WHERE Name='%s'"paramscurrent);
                                
mysql_tquery(mysql_dbquery"""");
                                
strmid(HouseInfo[housekey][hOwner],query,0,strlen(query),255);
                                
OnPropTextdrawUpdate(1housekey);
                                
SCM(playeridTEAM_GROVE_COLOR," test");
                            }
                            new 
query[128];
                            
mysql_format(mysql_dbquerysizeof query"SELECT * FROM `players` WHERE `Name` = '%s'"params);
                            
mysql_tquery(mysql_dbquery"ChangeName""is"playeridparams);
                            
//return 1;
                        
}
                        return 
1;
                    } 
Reply
#2

Can you identify your issue furthermore, how it doesn't save properly?


Also, why are you using 500 cells for that little query?
Reply
#3

I edited my post look please!
Reply
#4

PHP код:
mysql_tquery(mysql_dbquery"ChangeName""is"playeridparams); 
I don't think can do that with MySQL cause I've tried it before ;c instead do that:

Код:
new myname[MAX_PLAYERS][32];
then on change name command:
Код:
dcmd_changename(playerid, params[])
                    {
                        if(PlayerToPoint(3.0,playerid,358.5789,166.3685,1008.3828))
                        {
                            if(ChangedName[playerid] == 1) return SendClientMessage(playerid, COLOR_GREY, "testt");
                            if(isnull(params))
                            {
                                return SendClientMessage(playerid, -1, "/changename [new name]");
                            }
                            if(strlen(params) > MAX_PLAYER_NAME)
                            {
                                return SendClientMessage(playerid, -1, "Name has to have 24 caracters.");
                            }
                            new current[MAX_PLAYER_NAME];
                            GetPlayerName(playerid, current, sizeof current);
                            if(!strcmp(current, params, false))
                            {
                                return SendClientMessage(playerid, -1, "This is already your name!");
                            }
                            new housekey = PlayerInfo[playerid][pPhousekey];
                            if(PlayerInfo[playerid][pPhousekey] != 255)
                            {
                                new query[100];
                                format(query, sizeof(query), "UPDATE houseid SET Owner='%s' WHERE Name='%s'", params, current);
                                mysql_tquery(mysql_db, query, "", "");

                                strmid(HouseInfo[housekey][hOwner],query,0,strlen(query),255);
                                OnPropTextdrawUpdate(1, housekey);
                                SCM(playerid, TEAM_GROVE_COLOR," test");
                            }
                            format(myname[playerid],32,"%s",params);
                            new query[128];
                            mysql_format(mysql_db, query, sizeof query, "SELECT * FROM `players` WHERE `Name` = '%s'", params);
                            mysql_tquery(mysql_db, query, "ChangeName", "i", playerid);
                            //return 1;
                        }
                        return 1;
                    }
then on the call back:
Код:
forward ChangeName(playerid, newname[]);
public ChangeName(playerid, newname[]) {
    new rows, fields;
	cache_get_data(rows, fields, mysql);
	if(!rows) return SendClientMessage(playerid, -1, "This name doesn't exist!");
    new current[MAX_PLAYER_NAME];
    GetPlayerName(playerid, current, sizeof current);
    new query[128];
    mysql_format(mysql_db, query, sizeof query, "UPDATE `players` SET `Name` = '%s' WHERE `Name` = '%s'", myname[playerid], current);
    mysql_tquery(mysql_db, query);

    SetPlayerName(playerid, myname[playerid]);
    return 1;
}
Reply
#5

I put Jlalt cmd, at house I get "Property Owner: UPDATE houseid SET Owner='GoW' WHERE Name='GoW' "

and my name dosent get changed!
Reply
#6

dosent work..anyone?
Reply
#7

anyone please??
Reply
#8

This is why a proper relational model is important. Were the tables set up correctly you would only have had to change that name in the user's table and the change would automatically be cascaded through the database.

Using the name as a the key (WHERE name = ) is also very, very bad. Searching by name should only occur once when the player connects to find out the id of that user. All other statements should use that id. Want to find houses this player owns? Find it by their id.
Reply
#9

ok thx Vince for answering my post !
Reply
#10

but I still don't know how to do it.. I changed from Name to id everything good and dosent work..
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)