SQ lite register fail
#1

Hey,

I have just started using SQLite to save my users information, however when I register it doesn't save my users information why could this be?

I have tried all the tips for checking, I even debugged it and still nothing.

Here is my code:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    new query[256], DBResult: Result, PlayerName[MAX_PLAYER_NAME], IP[20];
    new Message[128];
    GetPlayerName(playerid,PlayerName,MAX_PLAYER_NAME);
    GetPlayerIp(playerid,IP,sizeof(IP));
    if(dialogid == DIALOG_LOGIN)
    {
        if(response)
        {
            format(query,sizeof(query),"SELECT * FROM `PlayerInfo` WHERE Username = '%s' AND Password = '%s'", DB_Escape(PlayerName), DB_Escape(inputtext));
            Result = db_query(Database, query);
            if(db_num_rows(Result))
            {
                new Field[20];
                db_get_field_assoc(Result, "Donator", Field, 30);
                PlayerInfo[playerid][pDonator] = strval(Field);

                db_get_field_assoc(Result, "AdminLevel", Field, 30);
                PlayerInfo[playerid][pAdminLevel] = strval(Field);

                db_get_field_assoc(Result, "Muted", Field, 30);
                PlayerInfo[playerid][pMuted] = strval(Field);

                db_get_field_assoc(Result, "Jailed", Field, 30);
                PlayerInfo[playerid][pJailed] = strval(Field);

                db_get_field_assoc(Result, "Jail Time", Field, 100);
                PlayerInfo[playerid][pJailTime] = strval(Field);

                db_get_field_assoc(Result, "Frozen", Field, 30);
                PlayerInfo[playerid][pFrozen] = strval(Field);

                db_get_field_assoc(Result, "Score", Field, 30);
                SetPlayerScore(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Money", Field, 30);
                Safe_GivePlayerMoney(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Kills", Field, 30);
                PlayerInfo[playerid][pKills] = strval(Field);

                db_get_field_assoc(Result, "Deaths", Field, 30);
                PlayerInfo[playerid][pDeaths] = strval(Field);

                db_get_field_assoc(Result, "WantedLevel", Field, 30);
                SetPlayerWantedLevel(playerid, strval(Field));

                db_get_field_assoc(Result, "Health", Field, 30);
                SetPlayerHealth(playerid, strval(Field));
               
                db_get_field_assoc(Result, "Armour", Field, 30);
                SetPlayerArmour(playerid, strval(Field));
               
                PlayerInfo[playerid][pLogged] = true;
                SendClientMessage(playerid, -1, ""COL_GREY"[SERVER]:{FFFFFF}You have "COL_GREEN" successfully{FFFFFF} logged in");
                return 1;
            }
            else
            {
                format(Message,sizeof(Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF}to the server, you're registered.\n\nPlease login by inputting your password.",ReturnPlayerName(playerid),playerid);
                ShowPlayerDialog(playerid,DIALOG_LOGIN,DIALOG_STYLE_INPUT,DIALOG_TITLE_LOGIN, Message, "Login", "Leave");
                SendClientMessage(playerid, -1, ""COL_RED"[ERROR]:{FFFFFF}You have entered the wrong password.");
                IncorrectPassword[playerid] ++;
                if(IncorrectPassword[playerid] == 5)
                {
                    ServerKick(playerid, "Incorrect Login");
                }
            }
        }
        else return ServerKick(playerid, "Incorrect Login");
    }
    if(dialogid == DIALOG_REGISTER)
    {
        if(response)
        {
            if(strlen(inputtext) > 24 || strlen(inputtext) < 3)
            {
                format(Message,sizeof(Message),"{FFFFFF}Welcome "COL_BLUE"%s(%d){FFFFFF}to the server, you're "COL_RED"not{FFFFFF} registered.\n\nPlease login by inputting your password.",ReturnPlayerName(playerid),playerid);
                ShowPlayerDialog(playerid,DIALOG_REGISTER,DIALOG_STYLE_INPUT,DIALOG_TITLE_LOGIN,Message, "Register", "Leave");
                SendClientMessage(playerid, -1, ""COL_RED"[ERROR]:{FFFFFF}Your password must contain atleast 3 characters and not exceed 24");
            }
            else
            {
                new BannedInfo[128];
                format(BannedInfo,sizeof(BannedInfo),"Not Banned");
                format(query,sizeof(query), "INSERT INTO `PlayerInfo`(Username, Password, Logged, Donator, AdminLevel, Muted, Banned, Jailed, JailTime, Frozen, IPAddress, Score, Money, Kills, Deaths, BannedBy, BannedReason, BannedDate,  WantedLevel, Health, Armour) VALUES('%s', '%s', 1, 0, 0, 0, 0, 0, 0, '%s', 0, 15000, 0, 0, '%s', '%s', '%s', 0, 100, 0)",
                DB_Escape(PlayerName),
                DB_Escape(inputtext),
                DB_Escape(IP),
                DB_Escape(BannedInfo),
                DB_Escape(BannedInfo),
                DB_Escape(BannedInfo));
                PlayerInfo[playerid][pLogged] = true;
                SendClientMessage(playerid, -1, "You have "COL_GREEN"successfully{FFFFFF} registered! You have been automatically logged in!");
                print("Registering Of User Has Been Successful");
                return 1;
            }
        }
        else return ServerKick(playerid, "Incorrect Login");
    }
    return 1;
}
Save User Code:

pawn Код:
stock SaveUser(playerid)
{
    new Query[500];
    new Float:Health, Float:Armour;
    GetPlayerHealth(playerid, Health);
    GetPlayerArmour(playerid, Armour);
    format(Query,sizeof(Query),"UPDATE `PlayerInfo` SET Donator = %d, AdminLevel = %d, Muted = %d, Jailed = %d, JailTime, Frozen = %d, IPAddress = %d, Score = %d, Money = %d, Kills = %d, Deaths = %d, WantedLevel = %s, Health = %f, Armour = %f WHERE Username='%s'",
    PlayerInfo[playerid][pDonator],
    PlayerInfo[playerid][pAdminLevel],
    PlayerInfo[playerid][pMuted],
    PlayerInfo[playerid][pJailed],
    PlayerInfo[playerid][pFrozen],
    PlayerInfo[playerid][pScore],
    PlayerInfo[playerid][pMoney],
    PlayerInfo[playerid][pKills],
    PlayerInfo[playerid][pDeaths],
    PlayerInfo[playerid][pWantedLevel],
    Health,
    Armour,
    ReturnPlayerName(playerid));
    print("Saving Player Was Successful");
    return 1;
}
By the way the printing was called;

Thanks,

Snowman
Reply
#2

You've said you tried debugging and it didn't work. How exactly? Debugging didn't show an error message?

Also, does it fail to save stats, or does it fail to register?


EDIT: in your save query, you're not using quotation marks, single quotes.

For example, you're doing:
Код:
WantedLevel = %s
while that should be:
Код:
WantedLevel = '%s'
This is probably the issue. Don't do this only for wanted level, do it for everything, just like you did after "WHERE."
Reply
#3

Haven't tried saving the players stats, it just fails to register the player into the database. So yeah I am guess it would fail saving stats as well however debugging doesn't always need an error. It's called for success as you can see.

Thanks,

Snowman
Reply
#4

new BannedInfo[12]; lol
BannedInfo = "Not Banned";

and where is
db_free_result(db_query(Database, query)); xd
Reply
#5

forgot the db_query lmfao thanks!
Reply
#6

Still doesn't work.
Reply
#7

http://forum.sa-mp.com/search.php?searchid=3910609
Reply
#8

yes I know I followed that tutorial it doesn't matter I have asked Lorenc to look at it .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)