Playerdata doesn't load correcly
#1

PHP код:
LoadPlayerData(playerid)
{
    
clearPlayerChat(playerid);
    new 
Data[2048],Field[258],idx;
    
mysql_queryF("SELECT * FROM `Accounts` WHERE `Username` = '%s' LIMIT 1"GetName(playerid));
    
mysql_store_result();
    if(
mysql_num_rows() == 1){
        
mysql_fetch_rowEx(Data);
        print(
Data);
        
Field strtukDataidx'|' );
        for(new 
0121s++)
        {
            switch(
s)
            {
                case 
0Player[playerid][UserID] = strval(Field);
                case 
2strmid(Player[playerid][Password],Field,0,strlen(Field),129);
                case 
3strmid(Player[playerid][LastIP],Field,0,strlen(Field),26);
                case 
4Player[playerid][Adminlevel] = strval(Field);
                case 
5Player[playerid][Money] = strval(Field);
                case 
6Player[playerid][RegTime] = strval(Field);
                case 
7Player[playerid][LastOn] = strval(Field);
                case 
8Player[playerid][Level] = strval(Field);
                case 
9Player[playerid][Gender] = strval(Field);
                case 
10Player[playerid][Age] = strval(Field);
                case 
11Player[playerid][Health] = floatstr(Field);
                case 
12Player[playerid][Armour] = floatstr(Field);
                case 
13Player[playerid][Skin] = strval(Field);
                case 
14strmid(Player[playerid][Country],Field,0,strlen(Field),255);
                case 
15Player[playerid][Test] = strval(Field);
                case 
16Player[playerid][Faction] = strval(Field);
                case 
17Player[playerid][FactionRank] = strval(Field);
                case 
18strmid(Player[playerid][FactionRankName],Field,0,strlen(Field),255);
                case 
19strmid(Player[playerid][Suspect], Field0strlen(Field), 255);
                case 
20Player[playerid][Arrest] = strval(Field);
                case 
21Player[playerid][PrisonSelect] = strval(Field);
                case 
22Player[playerid][PrisonTime] = strval(Field);
                case 
23Player[playerid][AdminPrisonCount] = strval(Field);
                case 
24Player[playerid][SecondsLoggedIn] = strval(Field);
                case 
25Player[playerid][PlayingHours] = strval(Field);
                case 
26Player[playerid][AdminCode] = strval(Field);
                case 
27Player[playerid][PhoneN] = strval(Field);
                case 
28Player[playerid][PhoneCredit] = strval(Field);
                case 
29Player[playerid][PhoneBook] = strval(Field);
                case 
30Player[playerid][House] = strval(Field);
                case 
31Player[playerid][Hotel] = strval(Field);
                case 
32Player[playerid][Hospitalized] = strval(Field);
                case 
33Player[playerid][OnDuty] = strval(Field);
                case 
34Player[playerid][DutyClothes] = strval(Field);
                case 
35Player[playerid][LastSkin] = strval(Field);
                case 
36Player[playerid][LastX] = floatstr(Field);
                case 
37Player[playerid][LastY] = floatstr(Field);
                case 
38Player[playerid][LastZ] = floatstr(Field);
                case 
39Player[playerid][LastA] = floatstr(Field);
                case 
40Player[playerid][LastInt] = strval(Field);
                case 
41Player[playerid][LastWorld] = strval(Field);
                case 
42Player[playerid][InFactionHQ] = strval(Field);
                case 
43Player[playerid][InHouse] = strval(Field);
                case 
44Player[playerid][Helper] = strval(Field);
                case 
45Player[playerid][Moderator] = strval(Field);
                case 
46strmid(Player[playerid][BankPincode],Field,0,strlen(Field),5);
                case 
47Player[playerid][BankNumber] = strval(Field);
                case 
48Player[playerid][BankMoney] = strval(Field);
                case 
49Player[playerid][ExperiencePoints] = strval(Field);
                case 
50Player[playerid][ExperiencePointsNeeded] = strval(Field);
                case 
51Player[playerid][Coins] = strval(Field);
                case 
52Player[playerid][WalkieTalkie] = strval(Field);
                case 
53Player[playerid][WalkieFrequency] = strval(Field);
                case 
54Player[playerid][HasMask] = strval(Field);
                case 
55Player[playerid][Banned] = strval(Field);
                case 
56Player[playerid][Bans] = strval(Field);
                case 
57Player[playerid][Kicks] = strval(Field);
                case 
58Player[playerid][WeaponSlot0] = strval(Field);
                case 
59Player[playerid][WeaponSlot1] = strval(Field);
                case 
60Player[playerid][WeaponSlot2] = strval(Field);
                case 
61Player[playerid][WeaponSlot3] = strval(Field);
                case 
62Player[playerid][WeaponSlot4] = strval(Field);
                case 
63Player[playerid][WeaponSlot5] = strval(Field);
                case 
64Player[playerid][WeaponSlot6] = strval(Field);
                case 
65Player[playerid][WeaponSlot7] = strval(Field);
                case 
66Player[playerid][WeaponSlot8] = strval(Field);
                case 
67Player[playerid][WeaponSlot9] = strval(Field);
                case 
68Player[playerid][WeaponSlot10] = strval(Field);
                case 
69Player[playerid][WeaponSlot11] = strval(Field);
                case 
70Player[playerid][WeaponSlot0Ammo] = strval(Field);
                case 
71Player[playerid][WeaponSlot1Ammo] = strval(Field);
                case 
72Player[playerid][WeaponSlot2Ammo] = strval(Field);
                case 
73Player[playerid][WeaponSlot3Ammo] = strval(Field);
                case 
74Player[playerid][WeaponSlot4Ammo] = strval(Field);
                case 
75Player[playerid][WeaponSlot5Ammo] = strval(Field);
                case 
76Player[playerid][WeaponSlot6Ammo] = strval(Field);
                case 
77Player[playerid][WeaponSlot7Ammo] = strval(Field);
                case 
78Player[playerid][WeaponSlot8Ammo] = strval(Field);
                case 
79Player[playerid][WeaponSlot9Ammo] = strval(Field);
                case 
80Player[playerid][WeaponSlot10Ammo] = strval(Field);
                case 
81Player[playerid][WeaponSlot11Ammo] = strval(Field);
                case 
82Player[playerid][DutyWeaponSlot0] = strval(Field);
                case 
83Player[playerid][DutyWeaponSlot1] = strval(Field);
                case 
84Player[playerid][DutyWeaponSlot2] = strval(Field);
                case 
85Player[playerid][DutyWeaponSlot3] = strval(Field);
                case 
86Player[playerid][DutyWeaponSlot4] = strval(Field);
                case 
87Player[playerid][DutyWeaponSlot5] = strval(Field);
                case 
88Player[playerid][DutyWeaponSlot6] = strval(Field);
                case 
89Player[playerid][DutyWeaponSlot7] = strval(Field);
                case 
90Player[playerid][DutyWeaponSlot8] = strval(Field);
                case 
91Player[playerid][DutyWeaponSlot9] = strval(Field);
                case 
92Player[playerid][DutyWeaponSlot10] = strval(Field);
                case 
93Player[playerid][DutyWeaponSlot11] = strval(Field);
                case 
94Player[playerid][DutyWeaponSlot0Ammo] = strval(Field);
                case 
95Player[playerid][DutyWeaponSlot1Ammo] = strval(Field);
                case 
96Player[playerid][DutyWeaponSlot2Ammo] = strval(Field);
                case 
97Player[playerid][DutyWeaponSlot3Ammo] = strval(Field);
                case 
98Player[playerid][DutyWeaponSlot4Ammo] = strval(Field);
                case 
99Player[playerid][DutyWeaponSlot5Ammo] = strval(Field);
                case 
100Player[playerid][DutyWeaponSlot6Ammo] = strval(Field);
                case 
101Player[playerid][DutyWeaponSlot7Ammo] = strval(Field);
                case 
102Player[playerid][DutyWeaponSlot8Ammo] = strval(Field);
                case 
103Player[playerid][DutyWeaponSlot9Ammo] = strval(Field);
                case 
104Player[playerid][DutyWeaponSlot10Ammo] = strval(Field);
                case 
105Player[playerid][DutyWeaponSlot11Ammo] = strval(Field);
                case 
106Player[playerid][AntiCheatExemption] = strval(Field);
                case 
107strmid(Player[playerid][Email],Field,0,strlen(Field),128);
                case 
108Player[playerid][Warns] = strval(Field);
                case 
109Player[playerid][Badge] = strval(Field);
                case 
110strmid(Player[playerid][SecretWord],Field,0,strlen(Field),128);
                case 
111Player[playerid][DisconnectReason] = strval(Field);
                case 
112Player[playerid][Business] = strval(Field);
                case 
113Player[playerid][FightStyle] = strval(Field);
                case 
114Player[playerid][SpawnedPersonalCar] = strval(Field);
                case 
115Player[playerid][DRIVINGLC] = strval(Field);
                case 
116Player[playerid][FIREARMSLC] = strval(Field);
                case 
117Player[playerid][BOATLC] = strval(Field);
                case 
118Player[playerid][BIKELC] = strval(Field);
            }
            
Field strtukDataidx'|' );
        }
        
clearPlayerChat(playerid);
        
SPD(playeridDIALOG_AUTHENTICATION);
        
TextDrawHideForPlayer(playeridText:LoadingTD);
        
//printf("%s",Player[playerid][SecretWord]);
        //printf("%s",Player[playerid][LastIP]);
        //printf("%s",PlayerConnectedIP[playerid]);
    
}else if(mysql_num_rows() == 0){
        
clearPlayerChat(playerid);
        new 
playernamesplit[3][MAX_PLAYER_NAME], Name[MAX_PLAYER_NAME];
        
GetPlayerName(playeridNamesizeof(Name));
        
split2(Nameplayernamesplit'_');
        if (!
strlen(playernamesplit[0]) || !strlen(playernamesplit[1]))
         {
              
KickWithMessage(playeridCOLOR_WHITE"Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
        
}
        else
        {
            
SPD(playeridDIALOG_REGISTER);
            
TextDrawHideForPlayer(playeridText:LoadingTD);
        }
    }
    
mysql_free_result();

PHP код:
  `UserIDint(11NOT NULL,
  `
Usernamevarchar(255) DEFAULT NULL,
  `
Passwordvarchar(129) DEFAULT NULL,
  `
LastIPvarchar(16NOT NULL DEFAULT '-1',
  `
Adminlevelint(4NOT NULL,
  `
Moneyint(10NOT NULL,
  `
RegTimeint(20NOT NULL,
  `
LastOnint(20NOT NULL,
  `
Levelint(4NOT NULL,
  `
Genderint(11NOT NULL,
  `
Ageint(3NOT NULL,
  `
Healthfloat NOT NULL,
  `
Armourfloat NOT NULL,
  `
Skinint(3NOT NULL,
  `
Countryvarchar(255NOT NULL,
  `
Testint(11NOT NULL DEFAULT '0',
  `
Factionint(11NOT NULL,
  `
FactionRankint(11NOT NULL,
  `
FactionRankNamevarchar(255NOT NULL,
  `
Suspectvarchar(255NOT NULL,
  `
Arrestint(11NOT NULL,
  `
PrisonSelectint(6NOT NULL DEFAULT '0',
  `
PrisonTimeint(6NOT NULL DEFAULT '0',
  `
AdminPrisonCountint(11NOT NULL DEFAULT '0',
  `
SecondsLoggedInint(11NOT NULL,
  `
PlayingHoursint(11NOT NULL,
  `
AdminCodeint(255NOT NULL,
  `
PhoneNint(6NOT NULL,
  `
PhoneCreditint(11NOT NULL,
  `
PhoneBookint(11NOT NULL DEFAULT '0',
  `
Houseint(11NOT NULL DEFAULT '0',
  `
Hotelint(11NOT NULL DEFAULT '0',
  `
Hospitalizedint(11NOT NULL DEFAULT '0',
  `
OnDutyint(11NOT NULL DEFAULT '0',
  `
DutyClothesint(11NOT NULL DEFAULT '0',
  `
LastSkinint(11NOT NULL,
  `
LastXfloat NOT NULL,
  `
LastYfloat NOT NULL,
  `
LastZfloat NOT NULL,
  `
LastAfloat NOT NULL,
  `
LastIntint(11NOT NULL,
  `
LastWorldint(11NOT NULL,
  `
InFactionHQint(11NOT NULL,
  `
InHouseint(11NOT NULL,
  `
Helperint(11NOT NULL DEFAULT '0',
  `
Moderatorint(11NOT NULL DEFAULT '0',
  `
BankPincodevarchar(5) DEFAULT '0',
  `
BankNumberint(11NOT NULL DEFAULT '0',
  `
BankMoneyint(11NOT NULL DEFAULT '0',
  `
ExperiencePointsint(11NOT NULL,
  `
ExperiencePointsNeededint(11NOT NULL DEFAULT '8',
  `
Coinsint(11NOT NULL DEFAULT '0',
  `
WalkieTalkieint(11NOT NULL DEFAULT '0',
  `
WalkieFrequencyint(11NOT NULL DEFAULT '0',
  `
HasMaskint(11NOT NULL DEFAULT '0',
  `
Bannedint(11NOT NULL DEFAULT '0',
  `
Bansint(11NOT NULL DEFAULT '0',
  `
Kicksint(11) DEFAULT '0',
  `
WeaponSlot0int(11NOT NULL DEFAULT '0',
  `
WeaponSlot1int(11NOT NULL DEFAULT '0',
  `
WeaponSlot2int(11NOT NULL DEFAULT '0',
  `
WeaponSlot3int(11NOT NULL DEFAULT '0',
  `
WeaponSlot4int(11NOT NULL DEFAULT '0',
  `
WeaponSlot5int(11NOT NULL DEFAULT '0',
  `
WeaponSlot6int(11NOT NULL DEFAULT '0',
  `
WeaponSlot7int(11NOT NULL DEFAULT '0',
  `
WeaponSlot8int(11NOT NULL DEFAULT '0',
  `
WeaponSlot9int(11NOT NULL DEFAULT '0',
  `
WeaponSlot10int(11NOT NULL DEFAULT '0',
  `
WeaponSlot11int(11NOT NULL DEFAULT '0',
  `
WeaponSlot0Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot1Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot2Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot3Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot4Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot5Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot6Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot7Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot8Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot9Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot10Ammoint(11NOT NULL DEFAULT '0',
  `
WeaponSlot11Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot0int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot1int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot2int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot3int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot4int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot5int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot6int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot7int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot8int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot9int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot10int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot11int(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot0Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot1Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot2Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot3Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot4Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot5Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot6Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot7Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot8Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot9Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot10Ammoint(11NOT NULL DEFAULT '0',
  `
DutyWeaponSlot11Ammoint(11NOT NULL DEFAULT '0',
  `
AntiCheatExemptionint(11NOT NULL DEFAULT '0',
  `
Emailvarchar(255NOT NULL,
  `
Warnsint(11NOT NULL DEFAULT '0',
  `
Badgeint(11NOT NULL DEFAULT '0',
  `
SecretWordvarchar(128NOT NULL,
  `
DisconnectReasonint(11NOT NULL,
  `
Businessint(11NOT NULL DEFAULT '-1',
  `
FightStyleint(11NOT NULL DEFAULT '0',
  `
SpawnedPersonalCarint(11NOT NULL DEFAULT '-1',
  `
DRIVINGLCint(11NOT NULL DEFAULT '0',
  `
FIREARMSLCint(11NOT NULL DEFAULT '0',
  `
BOATLCint(11NOT NULL DEFAULT '0',
  `
BIKELCint(11NOT NULL DEFAULT '0',
  `
LastOnDatevarchar(255NOT NULL,
  `
Offlineint(11NOT NULL DEFAULT '1'
ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
--
-- 
Dumping data for table `accounts`
--
INSERT INTO `accounts` (`UserID`, `Username`, `Password`, `LastIP`, `Adminlevel`, `Money`, `RegTime`, `LastOn`, `Level`, `Gender`, `Age`, `Health`, `Armour`, `Skin`, `Country`, `Test`, `Faction`, `FactionRank`, `FactionRankName`, `Suspect`, `Arrest`, `PrisonSelect`, `PrisonTime`, `AdminPrisonCount`, `SecondsLoggedIn`, `PlayingHours`, `AdminCode`, `PhoneN`, `PhoneCredit`, `PhoneBook`, `House`, `Hotel`, `Hospitalized`, `OnDuty`, `DutyClothes`, `LastSkin`, `LastX`, `LastY`, `LastZ`, `LastA`, `LastInt`, `LastWorld`, `InFactionHQ`, `InHouse`, `Helper`, `Moderator`, `BankPincode`, `BankNumber`, `BankMoney`, `ExperiencePoints`, `ExperiencePointsNeeded`, `Coins`, `WalkieTalkie`, `WalkieFrequency`, `HasMask`, `Banned`, `Bans`, `Kicks`, `WeaponSlot0`, `WeaponSlot1`, `WeaponSlot2`, `WeaponSlot3`, `WeaponSlot4`, `WeaponSlot5`, `WeaponSlot6`, `WeaponSlot7`, `WeaponSlot8`, `WeaponSlot9`, `WeaponSlot10`, `WeaponSlot11`, `WeaponSlot0Ammo`, `WeaponSlot1Ammo`, `WeaponSlot2Ammo`, `WeaponSlot3Ammo`, `WeaponSlot4Ammo`, `WeaponSlot5Ammo`, `WeaponSlot6Ammo`, `WeaponSlot7Ammo`, `WeaponSlot8Ammo`, `WeaponSlot9Ammo`, `WeaponSlot10Ammo`, `WeaponSlot11Ammo`, `DutyWeaponSlot0`, `DutyWeaponSlot1`, `DutyWeaponSlot2`, `DutyWeaponSlot3`, `DutyWeaponSlot4`, `DutyWeaponSlot5`, `DutyWeaponSlot6`, `DutyWeaponSlot7`, `DutyWeaponSlot8`, `DutyWeaponSlot9`, `DutyWeaponSlot10`, `DutyWeaponSlot11`, `DutyWeaponSlot0Ammo`, `DutyWeaponSlot1Ammo`, `DutyWeaponSlot2Ammo`, `DutyWeaponSlot3Ammo`, `DutyWeaponSlot4Ammo`, `DutyWeaponSlot5Ammo`, `DutyWeaponSlot6Ammo`, `DutyWeaponSlot7Ammo`, `DutyWeaponSlot8Ammo`, `DutyWeaponSlot9Ammo`, `DutyWeaponSlot10Ammo`, `DutyWeaponSlot11Ammo`, `AntiCheatExemption`, `Email`, `Warns`, `Badge`, `SecretWord`, `DisconnectReason`, `Business`, `FightStyle`, `SpawnedPersonalCar`, `DRIVINGSLC`, `FIREARMSLC`, `BOATLC`, `BIKELC`, `LastOnDate`, `Offline`); 
Its loading not like it should be, Everthing will be messed up,,
Reply
#2

What is that loop and switch() statement doing there with such a huge amount of numbers to check in the loop? Why are you mixing it up, do you know how SQL language works?

What version of MySQL do you use, I guess it's a non-threaded version. Here's how you should actually do it and trying to avoid being a cave-man programmer.

https://sampforum.blast.hk/showthread.php?tid=557276
Reply
#3

Bump
Reply
#4

@Riddick it isn't his code that is why.
Reply
#5

Just a few questions..
1, (Not a question, A statement) Your SQL Syn-taxing is fucking horrendous..

2, Silly question really but worth an ask.. - Are you sure it's sending the correct "Username"
Код:
 mysql_queryF("SELECT * FROM `Accounts` WHERE `Username` = '%s' LIMIT 1", GetName(playerid));
Question.
Is your TABLE spelled exactly: "Accounts" or is it "ACCOUNTS" or "accounts" , Some times tables will be spazzy if you don't put the exact name..

-
3, Why the hell are you sending an SQL statement and then responding to that statement in the same function..
Create a seperate function for that SQL to send the information too.
And then you can use the SQL statement in multiple locations and draw the information you need in separate functions, Looking @ that code makes me gag..
I can easily tell you're using multiple statements which do the exact same thing..
I don't have to see it to know it.. (More code = More time compiling = Looks ugly as fuck)

4, Quick observation.
You're putting loop statement in with the default value of 121, < Being max yet you've defined the max rows as 1..

Another observation
You NEVER once call information from the column it's stored in..
You're simply repeating a statement with no variable.. Namely: "Field"
Where does Field get it's data from because you're not telling the script where it's actually coming from
All you've done is throw a ton of enums @ the script with the value of "Field" well "Field has no value and it's not getting any value for that enum.
You're just switching case statements telling it the value = "Field".

That's why your code doesn't work.....


__
Side note:
Here is an EXAMPLE.. Of Clean and working code..

Код:
new SqlQuery[1024];
format(SqlQuery, sizeof(SqlQuery), "SELECT * FROM `Accounts` WHERE `username` = '%s'", Getname(playerid));
mysql_function_query(g_mysql_handle, SqlQuery, true, "LoadAccountInfo", "d",playerid);
Код:
forward LoadAccountInfo(playerid);
public LoadAccountInfo(playerid) {;	
	new accountname[MAX_PLAYER_NAME+1];
	new level, ph;
	new rows,fields;
	cache_get_data(rows,fields);
	if(rows < 1) {
		//Do Something if the account isn't found.
		return 1;
	}
	cache_get_row(0, 0, accountname);
	PlayerInfo[playerid][AccountName] = accountname;
	cache_get_row(0, 1, level);
	PlayerInfo[playerid][PlayerLevel] = level;
	cache_get_row(0, 2, ph);
	PlayerInfo[playerid][PlayingHours] = ph;
	return 1;
}
Obviously if we were Lazy we could just set a function Var to do all the work instead of individual names like accountname etc..
We could just create
Код:
new string[1024];
< and just call that for each row - assign it and then reuse it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)