MySQL with ENUM
#1

Hi,

I have a problem. I have made a mysql system for my users. What's wrong with this?
enum:
Код:
enum pInfo
{
	pUser[40],
	pPassword[40],
	pAdminLevel,
	pRank,
	pRankN[40],
	pScore,
	pMoney,
	pWorking,
	pFlyLicense,
	pRankC,
	pIp
}
new PlayerInfo[MAX_PLAYERS][pInfo];
new gPlayerLogged[MAX_PLAYERS];
new maxtries[MAX_PLAYERS];
This is the dialog response:
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 2)
	{
	    if(response)
	    {
	        if(!strlen(inputtext))
	        {
	            ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Register", "You don't have an account. Please Register.", "Register", "Cancel");
	            SendClientMessage(playerid, COLOR_RED, "You have to enter an password");
			}
			new PIP[50];
			new Query[300], Pname[24];
			GetPlayerName(playerid, Pname, 24);
			new escpname[24], escpass[100];
			mysql_real_escape_string(inputtext, escpass);
			mysql_real_escape_string(Pname, escpname);
			GetPlayerIp(playerid, PIP, 50);
			format(Query, sizeof(Query), "INSERT INTO `playerinfo` (`user`, `password`, `adminlevel`, `rank`, `rankn`, `score`, `money`, `working`, `flylicense`, `rankc`, `IP`) VALUES ('%s', '%s', 0, 0, 'Trucker Wannabe', 0, 5000, 0, 0, 0, '%s')", escpname, escpass, PIP); //Insert string
			mysql_query(Query);
			GameTextForPlayer(playerid, "~g~Registerd", 2000, 3);
			SendClientMessage(playerid, COLOR_YELLOW, "Registerd and logged in!");
			gPlayerLogged[playerid] = 1;
		}
	}
	if(dialogid == 1)
	{
	    if(response)
	    {
	        new Query[300], Pname[24];
	        GetPlayerName(playerid, Pname, 24);
	        new escpname[24];
	        mysql_real_escape_string(Pname, escpname);
	        format(Query, sizeof(Query), "SELECT * FROM `playerinfo` WHERE `user` = '%s' AND `password` = '%s'", escpname, inputtext);
	        mysql_query(Query);
	        mysql_store_result();
	        if(!mysql_num_rows())
	        {
	            SendClientMessage(playerid, COLOR_RED, "Wrong Password");
				maxtries[playerid] = maxtries[playerid] + 1;
				ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Login", "This account is registerd. please log in.", "Ok", "Cancel");
				if(maxtries[playerid] == 3)
				{
				    SendClientMessage(playerid, COLOR_RED, "Max tries exceeded!");
				    Kick(playerid);
				}
			}
			else
			{
			    new line[750];
			    if(mysql_fetch_row_format(line, "|"))
			    {
			        new var2[pInfo];
			        if(sscanf(line, "p<|>e<s[40]s[40]dds[40]ddddxs[40]>", var2))
			        {
			            SendClientMessage(playerid, COLOR_RED, "There is an error with loading your account.");
					}
					else
					{
					    SetPlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
					    SendClientMessage(playerid, COLOR_YELLOW, "Succesful logged in!");
					    gPlayerLogged[playerid] = 1;
					}
				}
			}
		}
	}

	return 1;
}
The problem is, he doesn't load the things from the database into the enum. So PlayerInfo[playerid][pAdminLevel] is 0. and PlayerInfo[playerid][pRankN] is nothing. The database is like this:
Код:
User | password | adminlevel | rank | rankn | score | money | working | rankc | IP
So the problem is that everything in the database doesn't load to the PlayerInfo. everything is filled in in the database.
Reply
#2

You load the data in to 'var2' - which is limited to the scope of your dialog.

pawn Код:
if(sscanf(line, "p<|>e<s[40]s[40]dds[40]ddddxs[40]>", PlayerInfo[playerid]))
You might also want to increase the length of your 'line' string as you continue to script your gamemode.
Reply
#3

@calg00ne, i already tried that, but it still doesn't work
Reply
#4

Do you know if your 'line' variable has any data in? Add print(line); to check.
Reply
#5

everything works, except the colors. It goes to Є127.0.0.1 when i log out
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)