Database not creating new users
#1

Whenever I join my server under another name, it just overwrites the previous account in the database.
Код:
stock RegisterPlayer(playerid, regpass[])
{
	new query[256], EncryptedPass[130];

	WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
    printf("player pass: %s",EncryptedPass);
	format(query, sizeof(query), "INSERT INTO users (Name, Password) VALUES ('%s', '%s')", GetName(playerid), EncryptedPass);
	mysql_query(query);
    printf("Player ID %d (%s) has been registered", playerid, GetName(playerid));
    SendClientMessage(playerid, -1, "Account registered!");
	LoginPlayer(playerid);

	return 1;
}
Reply
#2

Quote:
Originally Posted by CrystalMethod
Посмотреть сообщение
Whenever I join my server under another name, it just overwrites the previous account in the database.
Код:
stock RegisterPlayer(playerid, regpass[])
{
	new query[256], EncryptedPass[130];

	WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
    printf("player pass: %s",EncryptedPass);
	format(query, sizeof(query), "INSERT INTO users (Name, Password) VALUES ('%s', '%s')", GetName(playerid), EncryptedPass);
	mysql_query(query);
    printf("Player ID %d (%s) has been registered", playerid, GetName(playerid));
    SendClientMessage(playerid, -1, "Account registered!");
	LoginPlayer(playerid);

	return 1;
}
Hey,

First things first:

pawn Код:
query[256]
Do you really need 256 cells?

Код:
INSERT INTO users (Name, Password) VALUES ('', '')
alone takes only 50 characters.
Max player name length is 24 characters, and your encrypted password is saved in 130-cell-wide array (thus 130 characters).

In result, we've 50+24+130=204 cells (+1 for EOS terminator).

That means, that you waste 52 cells, which is..
Well, more than enough, if you're having huge script..

I just wanted to make a statement about this, as I am kind of sick of optimisation..

Anyways.

What is the schema of user table in Your database? Does it contain any primary key? It should, as this table should contain unique values (in some terms), and record id is a good example of such value.

With primary key, you won't bother with any overwritten data - instead, you will have to face data redundation, for example:

iduserpass
0SomeUserabcdefghij123456789
1AnotherUser123456789abcdefghij
2SomeUserSomeUserWithAnotherPass
So, user with ID 2 will have the same name as user with id 0, however: any data will be overwritten.
This problem could be solved by writing some method to determine if player's name is valid, in terms of if any other player with such a name have already registered in your server.. Well, this should be solved by login system, right..?

Good luck.
LetsOWN
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)