(error #1364) Field 'PlayerID' doesn't have a default value
#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


Messages In This Thread
(error #1364) Field 'PlayerID' doesn't have a default value - by Metharon - 28.01.2017, 17:02
Re: (error #1364) Field 'PlayerID' doesn't have a default value - by Divergent - 28.01.2017, 18:14
Re: (error #1364) Field 'PlayerID' doesn't have a default value - by AmigaBlizzard - 28.01.2017, 20:38

Forum Jump:


Users browsing this thread: 2 Guest(s)