Mysql Won't save in database
#1

If i put a password in register dialog then i check the database it don't create the account
here the pic of my database

OnPlayerConnect:
Код:
mysql_format(mysql, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
OnPlayerDisconnect:

Код:
    mysql_format(mysql, query, sizeof(query), "UPDATE `accounts` SET `Score`= %i WHERE `ID` = '%d'", GetPlayerScore(playerid), PlayerInfo[playerid][ID]);
    mysql_tquery(mysql, query, "", "");
Код:
public OnAccountCheck(playerid)
{
    new rows; //a variable that will be used to retrieve rows and fields in the database.
    cache_get_row_count(rows);//let's get the rows and fields from the database.
    if(rows) //if there is row
    {//then
        cache_get_value_name(0, "Password", PlayerInfo[playerid][Password],  129);
        //we will load player's password into pInfo[playerid][Password] to be used in logging in
        cache_get_value_name_int(0, "ID", PlayerInfo[playerid][ID]); //now let's load player's ID into pInfo[playerid][ID] so we can use it later
        printf("%s", PlayerInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password
        ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog
    }
    else //if we didn't find any rows from the database, that means, no accounts were found
    {
        ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
        //So we show them a dialog register
    }
    return 1;
}
forward OnAccountLoad(playerid);
public OnAccountLoad(playerid)
{
    cache_get_value_name_int(0, "Admin", PlayerInfo[playerid][pAdmin]);
    cache_get_value_name_int(0, "VIP", PlayerInfo[playerid][pVIP]);
    cache_get_value_name_int(0, "Score", PlayerInfo[playerid][Score]);
    cache_get_value_name_int(0, "Money", PlayerInfo[playerid][Money]);


    GivePlayerMoney(playerid, PlayerInfo[playerid][Money]);

    SendClientMessage(playerid, -1, "You have successfully logged in.");
    return true;
}
forward OnAccountRegister(playerid);
public OnAccountRegister(playerid)
{
    PlayerInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered.
    printf("TW Account ID: %d", PlayerInfo[playerid][ID]); //just for debugging.
    return 1;
}
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case LoginDialog:
        {
            if(!response) Kick(playerid);

            new
                hashpass[129],
                query[100],
                playername[MAX_PLAYER_NAME];

            GetPlayerName(playerid, playername, sizeof(playername));
            WP_Hash(hashpass, sizeof(hashpass), inputtext);
            if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
            {
                mysql_format(mysql, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
                mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                SendClientMessage(playerid, -1, "You have specified an incorrect password!");
                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
            }
        }
        case RegisterDialog:
        {
            if(!response) return Kick(playerid);
            if(strlen(inputtext) < 5)
            {
                SendClientMessage(playerid, -1, "Your password must at least contain more than 4 characters.");
                return ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, " Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
            }
            new
                query[512],
                playername[MAX_PLAYER_NAME],
                playerip[16];


            GetPlayerName(playerid, playername, sizeof(playername));
            GetPlayerIp(playerid, playerip, sizeof(playerip));
            WP_Hash(PlayerInfo[playerid][Password], 129, inputtext);
            mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)", playername, PlayerInfo[playerid][Password], playerip);
            mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid);
        }
    }
    return 1;
}
Reply


Messages In This Thread
Mysql Won't save in database - by DerickClark - 21.01.2017, 18:00
Re: Mysql Won't save in database - by Yaa - 21.01.2017, 18:05
Re: Mysql Won't save in database - by DerickClark - 21.01.2017, 18:08
Re: Mysql Won't save in database - by Yaa - 21.01.2017, 18:10
Re: Mysql Won't save in database - by ISmokezU - 21.01.2017, 18:13
Re: Mysql Won't save in database - by Yaa - 21.01.2017, 18:15
Re: Mysql Won't save in database - by DerickClark - 21.01.2017, 18:20
Re: Mysql Won't save in database - by Yaa - 21.01.2017, 18:22
Re: Mysql Won't save in database - by DerickClark - 21.01.2017, 18:28
Re: Mysql Won't save in database - by Vince - 21.01.2017, 19:26

Forum Jump:


Users browsing this thread: 1 Guest(s)