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

check

logs/error.log

or

logs/plugin/mysql.log

and give us logs
Reply
#3

my logs doesn't said anything
Reply
#4

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
my logs doesn't said anything
logs/plugin/mysql.log empty = impossible x 5899999999999*999999999999999999999999*99999999999 99

EDIT:

mysql_format Sucks !!

i used it many time and it's not fking working ! just use the normal format
Reply
#5

Re-read the tutorial that you used,i got started on this (https://sampforum.blast.hk/showthread.php?tid=574714). Also,120 for score is too much.
Reply
#6

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Re-read the tutorial that you used,i got started on this (https://sampforum.blast.hk/showthread.php?tid=574714). Also,120 for score is too much.
"[UPDATED 19/05/2015]"
Reply
#7

Hmm i debugged

Код:
    mysql_log(ALL);
    mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
    if(mysql_errno() != 0)
    {
        printf("[MySQL] The connection has failed.");
    }
    else
    {
        printf("[MySQL] The connection was successful.");
    }
it prints out

Код:
[MySQL] The connection has failed.
Reply
#8

Quote:
Originally Posted by DerickClark
Посмотреть сообщение
Hmm i debugged

mysql_log(ALL);
mysql = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
if(mysql_errno() != 0)
{
printf("[MySQL] The connection has failed.");
}
else
{
printf("[MySQL] The connection was successful.");
}

it prints out

[MySQL] The connection has failed.
check:

1- if you missed something (mysql info)

2- check phpmyadmin if it's work and login with account used for samp

3- check if user have privilages

4- check if allowed to login from localhost

5- check logs
Reply
#9

Not sure but still won't create the player accounts in the database.
Reply
#10

AUTO_INCREMENT attribute is not set on the ID column which means your insert fails. If logging is enabled then that should appear in the log.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)