Won't create a MySQL row on register
#1

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.
Reply
#2

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]);
Reply
#3

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

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;
}
Reply
#5

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
Reply
#6

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.
Reply
#7

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.
Reply
#8

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.
Reply
#9

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.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)