SA-MP Forums Archive
Won't create a MySQL row on register - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Won't create a MySQL row on register (/showthread.php?tid=413074)



Won't create a MySQL row on register - AphexCCFC - 04.02.2013

pawn Код:
stock MySQL_Register(playerid, passwordstring[])
{
    PlayerInfo[playerid][pCash] = 200;
    PlayerInfo[playerid][pLevel] = 1;
    PlayerInfo[playerid][pBank] = 500;
    PlayerInfo[playerid][pAdminLevel] = 0;
    new query[350], pname[24], IP[15];
    GetPlayerName(playerid, pname, 24);
    GetPlayerIp(playerid, IP, 15);
    format(query, sizeof(query), "INSERT INTO playerdata (Username, Password, Cash, Level, Bank, PosX, PosY, PosZ, PosA, IP, AdminLevel) VALUES('%s', SHA1('%s'), '%d', '%d', '%d', 1295, 183, 20, 97, '%s', '%d')", pname, passwordstring, PlayerInfo[playerid][pCash], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pBank], IP, PlayerInfo[playerid][pAdminLevel]);
    mysql_query(query);
    Logged[playerid] = 1;
    return 1;
}
If I set the Cash, Level, Bank and AdminLevels to numbers it works, but if I do it this way by using PlayerInfo variables, it doesn't create a new row in the MySQL table, weird.


Re: Won't create a MySQL row on register - T0pAz - 04.02.2013

Here you go.
pawn Код:
format(query, sizeof(query), "INSERT INTO playerdata (Username, Password, Cash, Level, Bank, PosX, PosY, PosZ, PosA, IP, AdminLevel) VALUES('%s', SHA1('%s'), %d, %d, %d, 1295, 183, 20, 97, '%s', %d)", pname, passwordstring, PlayerInfo[playerid][pCash], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pBank], IP, PlayerInfo[playerid][pAdminLevel]);



Re: Won't create a MySQL row on register - AphexCCFC - 04.02.2013

Lmao thanks, no sleep :/ I see what I've done wrong. I have one more thing if you can help with it, cheers.


Re: Won't create a MySQL row on register - AphexCCFC - 04.02.2013

I have this command:

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new string[256], playerb, level, query[300], playab[24];
    GetPlayerName(playerb, playab, 24);
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not logged in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 4)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have the privileges to use this command.");
        return 1;
    }
    if(sscanf(params, "ui", playerb, level))
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Usage{FFFFFF}: /makeadmin [playerid] [level]");
        return 1;
    }
    PlayerInfo[playerb][pAdminLevel] = level;
    format(query, sizeof(query), "UPDATE playerdata SET AdminLevel=%d WHERE Username='%s'", PlayerInfo[playerb][pAdminLevel], playab);
    mysql_query(query);
    format(string, sizeof(string), "Admin Notice{FFFFFF}: %s %s has made %s a Level %d Administrator.", AdminRank(playerid), Name(playerid), Name(playerb), level);
    SendAdminMessage(COLOR_LIGHTRED, 1, string);
    return 1;
}
The problem is, when I actually type /makeadmin 0 7
it says "Senior Admin Diego_Javier has made a Level 7 Administrator."
I look in the mysql database, admin level is still 5.
I can usually do this stuff but I need a bit of a boost with this one command and I'm set, cheers.

Stock for the Name(playerid) and Name(playerb) I have in the script is:

pawn Код:
stock Name(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}



Re: Won't create a MySQL row on register - T0pAz - 04.02.2013

Here you go.

pawn Код:
CMD:makeadmin(playerid, params[])
{
    new string[256], playerb, level, query[300];
    if(!IsPlayerLoggedIn(playerid))
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You are not logged in.");
        return 1;
    }
    if(PlayerInfo[playerid][pAdminLevel] < 4)
    {
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You do not have the privileges to use this command.");
        return 1;
    }
    if(sscanf(params, "ui", playerb, level))
    {
        SendClientMessage(playerid, COLOR_YELLOW, "Usage{FFFFFF}: /makeadmin [playerid] [level]");
        return 1;
    }
    PlayerInfo[playerb][pAdminLevel] = level;
    new strPName[MAX_PLAYER_NAME]; GetPlayerName(playerb, strPName, MAX_PLAYER_NAME);
    format(query, sizeof(query), "UPDATE playerdata SET AdminLevel=%d WHERE Username='%s'", PlayerInfo[playerb][pAdminLevel], strPName);
    mysql_query(query);
    format(string, sizeof(string), "Admin Notice{FFFFFF}: %s %s has made %s a Level %d Administrator.", AdminRank(playerid), Name(playerid), Name(playerb), level);
    SendAdminMessage(COLOR_LIGHTRED, 1, string);
    return 1;
}

Edit: Changed something, repaste it.
Edit: Changed once again, repaste it
Edit: Changed again once again, repaste it


Re: Won't create a MySQL row on register - AphexCCFC - 04.02.2013

Hmm, seems to be the same issue, tried different ways with no luck too :/

Your way gave me an error with 'playab' so I added it to new but still no luck.


Re: Won't create a MySQL row on register - T0pAz - 04.02.2013

Quote:
Originally Posted by AphexCCFC
Посмотреть сообщение
Hmm, seems to be the same issue, tried different ways with no luck too :/
I have edited the code. Try again.


Re: Won't create a MySQL row on register - AphexCCFC - 04.02.2013

Same problem, message says "Senior Admin Diego_Javier has made <blank here instead of the second name> a Level 7 Administrator" and doesn't update in MySQL.


Re: Won't create a MySQL row on register - T0pAz - 04.02.2013

Quote:
Originally Posted by AphexCCFC
Посмотреть сообщение
Same problem, message says "Senior Admin Diego_Javier has made <blank here instead of the second name> a Level 7 Administrator" and doesn't update in MySQL.
The updated code I posted should be okay. Try repasting and recompiling it and make sure your server is closed while you do so. If it's still not working, the problem is elsewhere.


Re: Won't create a MySQL row on register - AphexCCFC - 04.02.2013

Quote:
Originally Posted by T0pAz
Посмотреть сообщение
The updated code I posted should be okay. Try repasting and recompiling it and make sure your server is closed while you do so. If it's still not working, the problem is elsewhere.
Yeah I've tried the updated one, for some reason it doesn't recognise the "strPName". If I change it all to playerid instead of playerb, it works, but obviously that wouldn't be much good :P