Delete Account from MySQL not work?!
#1

I made a admin command to delete player account offline. Yeah, I'm having a trouble on the code, when I use the command, it always say that "can't find account" although I fill the account name correctly.
PHP код:
CMD:delaccount(playeridparams[]){
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playerid"You do not have permission to perform this command."TYPE_ERROR);
    if(
sscanf(params"s[24]"aName)) return System_Scm(playerid"/delaccount [Account Name]"TYPE_NOTICE);
    foreach(new 
iPlayer){
        if(!
strcmp(aNameGetPlayerNameEx(playerid))) {
            
format(stringsizeof(string), "Account [%s] is being used by Player ID [%d]"aNamei);
            
System_Scm(playeridstringTYPE_ERROR);
            return 
1;
        } 
    }
    new 
rows;
    
cache_get_row_count(rows);
    for(new 
row 0row rowsrow++){
        
cache_get_value_name(row"Username"szFieldName24);
        
printf("%s - %s"aNameszFieldName);
        if(!
strcmp(aNameszFieldName)) {
            
mysql_format(MHandlequerysizeof(query), "DELETE FROM `character` WHERE (`Username` = '%e') LIMIT 1"aName);
            
mysql_query(MHandlequery);
            
format(stringsizeof(string), "[%s] deleted [%s]"GetPlayerNameEx(playerid), aName);
            foreach(new 
iPlayer) {
                if(
Character[i][Admin] > 0System_Scm(playeridstringTYPE_SUCCESS);
            }
            return 
1;
        }    
    }
    
format(stringsizeof(string), "Can't find account [%s]"aName);
    
System_Scm(playeridstringTYPE_ERROR);
    return 
1;

I am using MySQL R41-2, the lastest version. I really need help!
Reply
#2

But does the message saying: name deleted? as well?
Reply
#3

No, it only says "cant find account", I don't know what problem this is.

And it doesn't print anything on the console.
Reply
#4

Seems like it's not getting past this line: if(!strcmp(aName, szFieldName)) {
try to print something random on the console, and tell us if it prints out that text: for example: it works. If it doesn't work, it means smt is wrong. Put it in that areea: {strcmp...}
Reply
#5

Quote:
Originally Posted by XStormiest
Посмотреть сообщение
Seems like it's not getting past this line: if(!strcmp(aName, szFieldName)) {
try to print something random on the console, and tell us if it prints out that text: for example: it works. If it doesn't work, it means smt is wrong. Put it in that areea: {strcmp...}
Like this, man?
PHP код:
CMD:delaccount(playeridparams[]){
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playeridPERMISSIONONLYTYPE_ERROR);
    
CMD:delaccount(playeridparams[]){ 
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128]; 
    if(
Character[playerid][Admin] < 4) return System_Scm(playerid"You do not have permission to perform this command."TYPE_ERROR); 
    if(
sscanf(params"s[24]"aName)) return System_Scm(playerid"/delaccount [Account Name]"TYPE_NOTICE); 
    foreach(new 
iPlayer){ 
        if(!
strcmp(aNameGetPlayerNameEx(playerid))) { 
            print(
"Being Used");
            
format(stringsizeof(string), "Account [%s] is being used by Player ID [%d]"aNamei); 
            
System_Scm(playeridstringTYPE_ERROR); 
            return 
1
        }  
    } 
    new 
rows
    
cache_get_row_count(rows); 
    for(new 
row 0row rowsrow++){ 
        
cache_get_value_name(row"Username"szFieldName24); 
        
printf("%s - %s"aNameszFieldName); 
        if(!
strcmp(aNameszFieldName)) { 
            print(
"Found");
            
mysql_format(MHandlequerysizeof(query), "DELETE FROM `character` WHERE (`Username` = '%e') LIMIT 1"aName); 
            
mysql_query(MHandlequery); 
            
format(stringsizeof(string), "[%s] deleted [%s]"GetPlayerNameEx(playerid), aName); 
            foreach(new 
iPlayer) { 
                if(
Character[i][Admin] > 0System_Scm(playeridstringTYPE_SUCCESS); 
            } 
            return 
1
        }     
    } 
            print(
"Can't find");
    
format(stringsizeof(string), "Can't find account [%s]"aName); 
    
System_Scm(playeridstringTYPE_ERROR); 
    return 
1

I did it but It still doesn't print anything on the console when I perform the command.


Now i edit something and when I fill the online player name, it says 'Being Used', and when I fill the offline player name, it says 'Can't find' although that name is exist in my database.
It also doesn't print "%s - %s", so why? It has no condition to be allowed to perform.

I have printed the total tows onto the console.
Quote:

cache_get_row_count(rows);
printf("%d", rows);

It prints '0' row, I'm sure that my total rows are more than.
Does it get the total rows failed? How can i make it gets succesfully?
Reply
#6

try
PHP код:
CMD:delaccount(playeridparams[]){
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playerid"You do not have permission to perform this command."TYPE_ERROR);
    if(
sscanf(params"s[24]"aName)) return System_Scm(playerid"/delaccount [Account Name]"TYPE_NOTICE);
    foreach(new 
iPlayer){
        if(!
strcmp(aNameGetPlayerNameEx(playerid))) {
            
format(stringsizeof(string), "Account [%s] is being used by Player ID [%d]"aNamei);
            
System_Scm(playeridstringTYPE_ERROR);
            return 
1;
        }
    }
    
mysql_format(MHande,query,sizeof(query),"SELECT `Username` FROM `character` WHERE `Username` = '%e'",aName);
    
mysql_query(MHandlequery);
    new 
rows;
    
cache_get_row_count(rows);
    if(
rows != 0) {
            
mysql_format(MHandlequerysizeof(query), "DELETE FROM `character` WHERE (`Username` = '%e') LIMIT 1"aName);
            
mysql_query(MHandlequery);
            
format(stringsizeof(string), "[%s] deleted [%s]"GetPlayerNameEx(playerid), aName);
            foreach(new 
iPlayer) {
                if(
Character[i][Admin] > 0System_Scm(playeridstringTYPE_SUCCESS);
            }
            return 
1;
        }
    }
    else
    {
        
format(stringsizeof(string), "Can't find account [%s]"aName);
        
System_Scm(playeridstringTYPE_ERROR);
    }
    return 
1;

Reply
#7

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
try
PHP код:
CMD:delaccount(playeridparams[]){
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playerid"You do not have permission to perform this command."TYPE_ERROR);
    if(
sscanf(params"s[24]"aName)) return System_Scm(playerid"/delaccount [Account Name]"TYPE_NOTICE);
    foreach(new 
iPlayer){
        if(!
strcmp(aNameGetPlayerNameEx(playerid))) {
            
format(stringsizeof(string), "Account [%s] is being used by Player ID [%d]"aNamei);
            
System_Scm(playeridstringTYPE_ERROR);
            return 
1;
        }
    }
    
mysql_format(MHande,query,sizeof(query),"SELECT `Username` FROM `character` WHERE `Username` = '%e'",aName);
    
mysql_query(MHandlequery);
    new 
rows;
    
cache_get_row_count(rows);
    if(
rows != 0) {
            
mysql_format(MHandlequerysizeof(query), "DELETE FROM `character` WHERE (`Username` = '%e') LIMIT 1"aName);
            
mysql_query(MHandlequery);
            
format(stringsizeof(string), "[%s] deleted [%s]"GetPlayerNameEx(playerid), aName);
            foreach(new 
iPlayer) {
                if(
Character[i][Admin] > 0System_Scm(playeridstringTYPE_SUCCESS);
            }
            return 
1;
        }
    }
    else
    {
        
format(stringsizeof(string), "Can't find account [%s]"aName);
        
System_Scm(playeridstringTYPE_ERROR);
    }
    return 
1;

Okay, I will reply you after tried but can you tell me the difference between '%e' and '%s'?
Reply
#8

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
try
PHP код:
CMD:delaccount(playeridparams[]){
    new 
aName[MAX_PLAYER_NAME], szFieldName[MAX_PLAYER_NAME], query[256], string[128];
    if(
Character[playerid][Admin] < 4) return System_Scm(playerid"You do not have permission to perform this command."TYPE_ERROR);
    if(
sscanf(params"s[24]"aName)) return System_Scm(playerid"/delaccount [Account Name]"TYPE_NOTICE);
    foreach(new 
iPlayer){
        if(!
strcmp(aNameGetPlayerNameEx(playerid))) {
            
format(stringsizeof(string), "Account [%s] is being used by Player ID [%d]"aNamei);
            
System_Scm(playeridstringTYPE_ERROR);
            return 
1;
        }
    }
    
mysql_format(MHande,query,sizeof(query),"SELECT `Username` FROM `character` WHERE `Username` = '%e'",aName);
    
mysql_query(MHandlequery);
    new 
rows;
    
cache_get_row_count(rows);
    if(
rows != 0) {
            
mysql_format(MHandlequerysizeof(query), "DELETE FROM `character` WHERE (`Username` = '%e') LIMIT 1"aName);
            
mysql_query(MHandlequery);
            
format(stringsizeof(string), "[%s] deleted [%s]"GetPlayerNameEx(playerid), aName);
            foreach(new 
iPlayer) {
                if(
Character[i][Admin] > 0System_Scm(playeridstringTYPE_SUCCESS);
            }
            return 
1;
        }
    }
    else
    {
        
format(stringsizeof(string), "Can't find account [%s]"aName);
        
System_Scm(playeridstringTYPE_ERROR);
    }
    return 
1;

It worked! Thank you very much. And can you tell me, after get a row count, I must select something first?
Reply
#9

Use mysql_tquery and its return values to format the message if the query was succesful or not. And you shouldn't delete accounts with non-threaded queries.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)