PDA

View Full Version : mysql (strickenKid) wont load data


CounterTerroristUnit
01/09/2011, 06:28 PM
hi,

saving on disconnect and registring works fine and is inserted into the right table but as soon as a already registered player trys to log in it fails.
Well, the password also works, cause when i enter the right password on login it says login successful and it proceeds.

But it fails when it comes to the other data.
The log says:


mysql_fetch_field could not find field name "NULL".


This is the code:

new query[1400], pname[24], savingstring[1400];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT Score, Money, Kills, Deaths, Admin FROM Users WHERE name = '%s'", pname);
mysql_query(query);
mysql_store_result();
mysql_fetch_row(query,"|");
{
mysql_fetch_field(savingstring, "Score"); SetPlayerScore(playerid, strval(savingstring));
mysql_fetch_field(savingstring, "Money"); MoneyCash[playerid] = strval(savingstring);
mysql_fetch_field(savingstring, "Kills"); kills[playerid] = strval(savingstring);
mysql_fetch_field(savingstring, "Deaths"); deaths[playerid] = strval(savingstring);
mysql_fetch_field(savingstring, "Admin"); Player[playerid][AdminLevel] = strval(savingstring);
//...
}
mysql_free_result();


help would be great :p

//edit: +Reps for people that help me ;)

[MWR]Blood
01/09/2011, 06:41 PM
You could use sscanf to store the data, a lot easier!

CounterTerroristUnit
01/09/2011, 06:47 PM
could u give me an example pls:D

[MWR]Blood
01/09/2011, 06:50 PM
Taken from my script.

stock LoadStats(playerid)
{
format(Query, sizeof(Query), "SELECT FROM `YOUR_TABLE_HERE` WHERE `Username` = '%s'", GetPName(playerid));
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query, "|");
sscanf(Query, "e<p<|>ds[23]s[30]s[16]iiiiiiiiiiiii>", PInfo[playerid]);//the MySQL table structure, in the order how it is
mysql_free_result();
return 1;
}

CounterTerroristUnit
01/09/2011, 07:14 PM
thx alot could u also show me the part of ur script where u check the players entered password pls?
would be great. :p

Joe Staff
01/09/2011, 07:16 PM
Also you didn't set "savestring" to anything.


Edit: nevermind, lol. I haven't worked with SQL in a while

CounterTerroristUnit
01/09/2011, 10:21 PM
mhh im kinda new to mysql so i need ur help guys :p

i got this error messages printed in the server logs:


[00:12:03] [MySQL] Error (0): Failed to exeute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.
[00:12:03] [MySQL] Error (0): Function: mysql_store_result called when no prior successful query executed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.
[00:12:03] [MySQL] Error (0): Function: mysql_store_result called when no result stored. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.
[00:12:17] [MySQL] Error (0): Failed to exeute query. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.
[00:12:17] [MySQL] Error (0): Function: mysql_store_result called when no prior successful query executed. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.
[00:12:17] [MySQL] Error (0): Function: mysql_store_result called when no result stored. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM `Users` WHERE `name` = 'TestPlayer'' at line 1.


this is the pawno part:


new Query[1400], pname[24];
GetPlayerName(playerid, pname, 24);
format(Query, sizeof(Query), "SELECT FROM `Users` WHERE `name` = '%s'", pname);
mysql_query(Query);
mysql_store_result();
mysql_fetch_row(Query, "|");
sscanf(Query, "ddd",MoneyVar[playerid],kills[playerid],deaths[playerid]);
mysql_free_result();



so can u tell me why i keep getting this errors?
Would be very happy to be able to give u guys some Reps+ :p

and also when i spawn i get no money or kills loaded from the file it thinks im a new player without any score.

iggy1
01/09/2011, 10:23 PM
Try this
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `name` = '%s'", pname);

You wasn't selecting any data.

EDIT: Oh and change this too.
sscanf(Query, "p<|>ddd",MoneyVar[playerid],kills[playerid],deaths[playerid]);

CounterTerroristUnit
01/09/2011, 10:37 PM
thx alot iggy :p
no more log errors :p

but theres still a problem...


//edit: nvm, its fixed.

login works now but i dont receive the money after login.
Are u sure i dont need to add more to this? :


new Query[1400], pname[24];
GetPlayerName(playerid, pname, 24);
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `name` = '%s'", pname);
mysql_query(Query);
mysql_store_result();
mysql_fetch_row(Query, "|");
sscanf(Query, "p<|>dddd",SetPlayerScore(playerid),MoneyVar[playerid],kills[playerid],deaths[playerid]);
mysql_free_result();

is that really all i need to do to load my saved stats?
Also i dont know how to load the score, so help would be much appreciated. :p