MySQL not saving
#1

-solved-
Reply
#2

First problem: You are checking it wrong. If IsPlayerAdmin then return that he isn't. Use the ! (not) operator

https://sampwiki.blast.hk/wiki/Control_Structures#Operators

Second problem:

Mysql WHERE syntax works this way:

Код:
WHERE column | operator | value
Код:
WHERE name='%s'
Reply
#3

pawn Код:
CMD:makeleader(playerid, params[])
{
    new
        targetid,
        factionid,
        string[128],
        targetname[24],
        playername[24]
    ;

    if(sscanf(params, "ui", targetid, factionid))
        return SendClientMessage(playerid, -1, "Usage: /makeleader [playerid] [factionid]");
   
    if(IsPlayerAdmin(playerid) || pInfo[playerid][pAdmin] <= 5)
        return SendClientMessage(playerid, -1, "You are not an admin");

    if(!IsPlayerConnected(targetid))
        return SendClientMessage(playerid, -1, "Invalid playerid!");

    if(0 > factionid > 3) return SendClientMessage(playerid, -1, "Invalid factionid.  Factionid's: 1-3");

    GetPlayerName(playerid, playername, sizeof(playername)), GetPlayerName(targetid, targetname, sizeof(targetname));

    format(string, sizeof(string), "You made %s leader of faction id %i!", targetname, factionid);
    SendClientMessage(playerid, -1, string);

    format(string, sizeof(string), "You were made leader of faction id %i by %s", factionid, playername);
    SendClientMessage(playerid, -1, string);

    pInfo[playerid][pFaction] = factionid;
    pInfo[playerid][pFactionRank] = 6;

    format(string, sizeof(string), "UPDATE `playerdata` SET `faction` = %i, `frank` = %i WHERE `nick` = '%s' ", pInfo[playerid][pFaction], pInfo[playerid][pFactionRank], playername);
    mysql_query(string);
    return true;
}
EDIT: Late but provided the right code
Reply
#4

I've also been having trouble with my SavePlayer function.
Errors:
Код:
[Sat Dec 14 22:54:53 2013] Function: mysql_query executed: "UPDATE `playerdata` SET `admin` = '6' WHERE `id` = '1470' LIMIT 1" with result: "0".
[Sat Dec 14 22:55:19 2013] Function: mysql_query executed: "UPDATE playerdata SET `admin` = '6', `score` = '0', `money` = '0', `cookies` = '0', `kills` = '0', `deaths` = '0' `faction` = '0', `family` = '0', `job` = '0', `fleader` = '0', `frank` = '0', WHERE `id` = '1470' LIMIT 1" with result: "1".
Code
pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] == 1)
    // checks if the player is logged
    {
        new Query[500];
        format(Query, 500, "UPDATE playerdata SET `admin` = '%d', `score` = '%d', `money` = '%d', `cookies` = '%d', `kills` = '%d', `deaths` = '%d' `faction` = '%d', `family` = '%d', `job` = '%d', `fleader` = '%d', `frank` = '%d', WHERE `id` = '%d' LIMIT 1",
        pInfo[playerid][pAdmin],
        pInfo[playerid][pScore],
        pInfo[playerid][pMoney],
        pInfo[playerid][pCookies],
        pInfo[playerid][pKills],
        pInfo[playerid][pDeaths],
        pInfo[playerid][pFaction],
        pInfo[playerid][pFamily],
        pInfo[playerid][pJob],
        pInfo[playerid][pFactionLeader],
        pInfo[playerid][pFactionRank],
        pInfo[playerid][ID]);
        mysql_query(Query);
    }
}
EDIT: Thanks btw for helping 'pds2k12' +REP
Reply
#5

Quote:
Originally Posted by Jimmy0wns
Посмотреть сообщение
I've also been having trouble with my SavePlayer function.
Errors:
Код:
[Sat Dec 14 22:54:53 2013] Function: mysql_query executed: "UPDATE `playerdata` SET `admin` = '6' WHERE `id` = '1470' LIMIT 1" with result: "0".
[Sat Dec 14 22:55:19 2013] Function: mysql_query executed: "UPDATE playerdata SET `admin` = '6', `score` = '0', `money` = '0', `cookies` = '0', `kills` = '0', `deaths` = '0' `faction` = '0', `family` = '0', `job` = '0', `fleader` = '0', `frank` = '0', WHERE `id` = '1470' LIMIT 1" with result: "1".
Code
pawn Код:
Code..
EDIT: Thanks btw for helping 'pds2k12' +REP
I need more information, also pFactionLeader is a string right? so as the pFaction and pFamily, recheck your code if you are using the right placeholder
Reply
#6

Quote:
Originally Posted by pds2k12
Посмотреть сообщение
I need more information, also pFactionLeader is a string right? so as the pFaction and pFamily, recheck your code if you are using the right placeholder
I removed pFactionLeader from the table and script now too, as i don't need it anymore.

And yes, everything is in the right way it should be, although the pFaction are from 1 to 6 for example.
Reply
#7

Should be this:

pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] == 1)
    // checks if the player is logged
    {
        new Query[500];
        format(Query, 500, "UPDATE playerdata SET `admin` = '%d', `score` = '%d', `money` = '%d', `cookies` = '%d', `kills` = '%d', `deaths` = '%d', `faction` = '%d', `family` = '%d', `job` = '%d', `fleader` = '%d', `frank` = '%d' WHERE `id` = '%d' LIMIT 1",
        pInfo[playerid][pAdmin],
        pInfo[playerid][pScore],
        pInfo[playerid][pMoney],
        pInfo[playerid][pCookies],
        pInfo[playerid][pKills],
        pInfo[playerid][pDeaths],
        pInfo[playerid][pFaction],
        pInfo[playerid][pFamily],
        pInfo[playerid][pJob],
        pInfo[playerid][pFactionLeader],
        pInfo[playerid][pFactionRank],
        pInfo[playerid][ID]);
        mysql_query(Query);
    }
}
Reply
#8

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Should be this:

pawn Код:
SavePlayer(playerid)
{
    if(pInfo[playerid][Logged] == 1)
    // checks if the player is logged
    {
        new Query[500];
        format(Query, 500, "UPDATE playerdata SET `admin` = '%d', `score` = '%d', `money` = '%d', `cookies` = '%d', `kills` = '%d', `deaths` = '%d', `faction` = '%d', `family` = '%d', `job` = '%d', `fleader` = '%d', `frank` = '%d' WHERE `id` = '%d' LIMIT 1",
        pInfo[playerid][pAdmin],
        pInfo[playerid][pScore],
        pInfo[playerid][pMoney],
        pInfo[playerid][pCookies],
        pInfo[playerid][pKills],
        pInfo[playerid][pDeaths],
        pInfo[playerid][pFaction],
        pInfo[playerid][pFamily],
        pInfo[playerid][pJob],
        pInfo[playerid][pFactionLeader],
        pInfo[playerid][pFactionRank],
        pInfo[playerid][ID]);
        mysql_query(Query);
    }
}
Thanks, please move this to the archive.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)