(error #1364) Field 'PlayerID' doesn't have a default value
#1

I've been taking a break from scripting for a year. Last time i checked my gamemode was working 100%..

Now it seems my register it's not working anymore , i don't understand why.

The problem is that cache insert id is not returning anything.

(error #1364) Field 'PlayerID' doesn't have a default value

pawn Код:
if(strlen(inputtext))
            {
                new query[1000];
                PlayerInfo[playerid][pLanguage] = Language[playerid];
                format(PlayerInfo[playerid][pPassword], 256, inputtext);
                mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` ( `Username`, `Password`, `Language`) VALUES ('%s', '%s', '%d')", GetName(playerid), inputtext, Language[playerid]);
                mysql_tquery(mysql, query, "RegisterAccountInfo", "i", playerid);
            }

pawn Код:
script RegisterAccountInfo(playerid)
{
    PlayerInfo[playerid][pID] = cache_insert_id();
    PlayerInfo[playerid][pLevel] = 1;
    new strglobal[856];
    if(Language[playerid] == EN)
    {
        format(strglobal,sizeof(strglobal), "{FFFFFF}Question : Your character is male or female ?");
        ShowPlayerDialogEx(playerid,DIALOG_SEX,DIALOG_STYLE_MSGBOX,"SERVER: {FFFFFF}GENDER",strglobal,"Male","Female");
    }
    if(Language[playerid] == RO)
    {
        format(strglobal,sizeof(strglobal), "{FFFFFF}Оntrebare : Personajul tгu este femeie sau bгrbat ?");
        ShowPlayerDialogEx(playerid,DIALOG_SEX,DIALOG_STYLE_MSGBOX,"SERVER: {FFFFFF}GENDER",strglobal,"Bгrbat","Femeie");
    }
    CC(playerid, 10);
    new query[456];
    format(query,sizeof(query), "UPDATE accounts SET IsConnected = 1, PlayerID = %d where ID = %d", cache_insert_id(), playerid);
    mysql_tquery(mysql, query, "", "");
}
Did i miss something ? I need to update the MySQL is r39-2 .
Reply
#2

You're making your system way more complicated than it needs to be. The way I see it you already have access to the player's playerid in game, why save it in your database when it is only accessed when online? Why not just auto increment?
Reply
#3

Never save the playerid.
When you connect, you can have playerid 5. When you logout and login later, you might have playerid 22.
And you'll be loading/updating someone else's account.

When you create an account, insert the name and password (and language).
Let mysql figure out a UserID (your pID) which is unique by setting the ID column to auto-increment.

When loading the account, load that UserID into your enum array and ALWAYS use that UserID to update stuff instead of a playerid.
That way, you'll always update the proper account.
A playerid is only valid for online players and will be re-used very often by any player.
A UserID is linked to one player only and will never change.



Also, when saving playerdata like his name, NEVER use %s in mysql_format. Use %e instead to escape the name and prevent SQL injection.
Otherwise, any player might be able to create a username that deletes your database.

And you don't have to update the database and save if the player is online or not.
Just loop through all players and see if they're connected instead of later sending a query to check if they're online, it's much faster with a loop instead of a query.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)