MySQL Problem with storing the right result
#1

Hi, I am getting a small problem with MySQL, I am still new to it so I have a hard time trying to create query's.

I am trying to update a player's admin level with this cmd.

pawn Код:
CMD:setlevel(playerid, params[])
{
    new
        id,
        level,
        str[128]
    ;
    if(PlayerInfo[playerid][Admin] >= 5 || RconAdmin(playerid))
    {
        if(sscanf(params, "ui", id, level))
        {
            return SendClientMessage(playerid, LBLUE, "USAGE: /setlevel (playerid) (level)") &&
            SendClientMessage(playerid, GREEN, "Function: Set a person a admin");
        }
        format(str, sizeof(str), "UPDATE `playerinfo` SET `Admin` = '%d' WHERE `User` = '%s'", level, pName(id));
        mysql_query(str);
        mysql_store_result();
        format(str, sizeof(str), "|- Administrator %s has made %s (%d) admin level %d -|", pName(playerid), pName(id), id, level);
        SendClientMessageToAll(ORANGE, str);
        mysql_free_result();
    }
    else SendClientMessage(playerid, RED, "ERROR: You are not an admin!");
    return 1;
}
I seem to get no errors when compiling but when I use the command in-game, I get a error in the console:

[MySQL] Error (0): Failed to store result.

and when I look in the MySQL Log it will be this :

Код:
[Tue Aug 10 09:38:41 2010] Function: mysql_query executed: "UPDATE `playerinfo` SET `Admin` = '5' WHERE `User` = 'Toni'" with result: "0".
[Tue Aug 10 09:38:41 2010] Function: mysql_store_result executed with result: "0"
[Tue Aug 10 09:38:41 2010] Error (0): Failed to store result.
[Tue Aug 10 09:38:41 2010] Function: mysql_free_result executed.
So something is wrong with my query, it turns out, it will set every other's username to 0.

Can someone help me make it effect only 1 person?

Thanks again,
Toni
Reply
#2

bump......plz help.
Reply
#3

pawn Код:
mysql_store_result();
mysql_free_result();
Remove both of these, there's no need to use them since you're not fetching anything from the database, you're only setting new information so there won't be a result.

The reason for it setting everyone elses to 0 could be because you're pName function isn't working as intended. Also there's no need to have an integer in quotes '%d', you should just leave it as %d
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)