Query isnt working
#1

Код:
	public OnPlayerConnect(playerid)
	{
		GetPlayerName(playerid, Name[playerid], (24 + 1));
		GetPlayerIp(playerid, PlayerIP[playerid], (15+1));
		LoadMappings(playerid);
		TogglePlayerSpectating(playerid, true);
		
		CrashCheckTimer[playerid] = SetTimerEx("CheckSpeed", 100, 1, "i", playerid);
		
		IsPlayerNameNonRP(Name[playerid]);
		SetPlayerColor(playerid, COLOR_WHITE);

		LoadPlayerTextDraws(playerid);

		if(!IsPlayerNPC(playerid))
		{
			new query[128];
			mysql_format(sqlHandle, query, sizeof(query), "SELECT `Password`, `ID` FROM `samp_users` WHERE `Username` = '%e'", Name[playerid]);
			mysql_tquery(sqlHandle, query, "OnPlayerConnectMessage", "i", playerid);
			
			print(query);

			SendClientMessage(playerid, COLOR_GREEN, "Welcome to "GAMEMODE_NAME". © "SERVER_OWNER" and "SERVER_DEVELOPER"");
		}
		return 1;
	}
The "SELECT `PASSWORD`, `ID` FROM `samp_users" query isnt wokring :

Код:
	Function:OnPlayerConnectMessage(playerid)
	{
		new rows, fields;
		
		cache_get_data(rows, fields);
		
			cache_get_field_content(0, "Password", Account[playerid][Password]);
			printf("PASS: %s", Account[playerid][Password]);
		
		new string[255];
		
		if(rows)
		{

			if(!isnull(string)) format(string, sizeof(string), "%s", EOS);
			format(string, sizeof(string), "{FFFFFF}Welcome back to {0080C0}"GAMEMODE_NAME"{FFFFFF}, {C0C0C0}%s{FFFFFF}.\n\nPlease enter your {FF0000}password below.{000000}\n{FFFFFF}", GetNameWithSpace(playerid));
			ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "{FFFFFF}Welcome to {008080}"GAMEMODE_NAME"", string, "Login", "Quit");

		}
		else
		{
			if(!isnull(string)) format(string, sizeof(string), "%s", EOS);
			format(string, sizeof(string), "{00FF00}Welcome to {008000}"GAMEMODE_NAME"{00FF00}, {008000}%s{00FF00}.\n\n{FFFFFF}We are glad to have you registering here at our server.\n\nYour registration process is simple: \n\n{FFFFFF}1) Type your desired password\n2) Go through the quiz\n", GetNameWithSpace(playerid));
			ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "{FFFFFF}Welcome to {0080C0}"GAMEMODE_NAME"", string, "Register", "Quit");
		}
		return 1;
	}
cache_get_field_content(0, "Password", Account[playerid][Password]);
printf("PASS: %s", Account[playerid][Password]);

That isn't working, it just prints "PASS:"
Reply
#2

What does it say in the mysql_log?
Reply
#3

Nothing. If the MySQL log had said something I would have stated it.
Reply
#4

https://sampwiki.blast.hk/wiki/MySQL/R33..._field_content
Checkout the comment for that function.

You NEED to specify the length when storing data inside an enumerated array.
Reply
#5

What, so I just use
Quote:

sizeof(Accounts[playerid][Password])

?
Reply
#6

You would, but due to bug/feature in pawn compiler sizeof doesn't work for 2d arrays as you would expect. You can:
1. Simply use constant number equal to your password length
2. Define a constant:
pawn Код:
#define MAX_PASSWORD_LENGTH (128)

//say in your enum
enum E_PLAYER_DATA {
    //(...)
    Password[MAX_PASSWORD_LENGTH],
    //(...)
}
And then use MAX_PASSWORD_LENGTH.

Word of advice: avoid using common words in your enums, as you'll run into a lot of namespace clashes. I'd recommend something like
pawn Код:
//Do not do this
enum Player {
    Password
}
//Do this
enum E_PLAYER {
    E_PLAYER_PASSWORD
}
3. Use Zeex's compiler with this bug fixed
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)