Mysql Saving Data -
Stefand - 06.05.2013
Hello, So today I have started working with Mysql and I understand it for a big part now but I still can't figure out why It doesn't save all of the things I want it to save.
pawn Code:
enum PlayerStats
{
UserID,
Username[MAX_PLAYER_NAME],
Password[129],
LastIP[25],
Adminlevel,
Money,
RegTime,
LastOn,
Level,
Gender[7],
Age,
Float: Health,
Float: Armour,
Skin,
}
stock SaveVariables(playerid)
{
if(Authenticated[playerid])
{
new
query[9999],
Float:pFloatValue[2];//don't forget to change the "2" to "5" when enabling the last pos
GetPlayerHealth(playerid, pFloatValue[0]);
GetPlayerArmour(playerid, pFloatValue[1]);
//GetPlayerPos(playerid, pFloatValue[2], pFloatValue[3], pFloatValue[4]);
format(query, sizeof(query), "UPDATE `Accounts` SET `adminLevel` = %d, `Money` = %d, `Level` = %d,`LastOn` = %d, `Health` = %f, `Armour` = %f, `Skin` = %d' `Gender` = '%s', `LastIP` = %s AND `Age` = %d WHERE `Username` = '%s'",
Player[playerid][Adminlevel],
real_GetPlayerCash(playerid),
Player[playerid][Level],
gettime(),
pFloatValue[0],
pFloatValue[1],
Player[playerid][Skin],
Player[playerid][Gender],
PlayerIP[playerid],
Player[playerid][Age],
GetName(playerid));
mysql_function_query(connectionHandle, query, false, "DefaultCallback", "");
}
return 1;
}
I don't get any error codes or anything but it does not save: LastIP, Health, Armour, LastOn, Skin.
I use BlueG R7's MySql.
Re: Mysql Saving Data -
Vince - 06.05.2013
Quote:
Originally Posted by Stefand
I don't get any error codes or anything
|
That's odd, because you should be getting errors. Your query is wrong. You don't have the %s of LastIp between quotes, which is a must for strings. Secondly, the list is of values is to be separated by commas only. No AND is required.
Re: Mysql Saving Data -
Pooh7 - 06.05.2013
You probably don't get any errors because you haven't enabled MySQL logging.
Add the following line right above your mysql_connect function:
pawn Code:
mysql_log(LOG_ERROR | LOG_WARNING);
As regards the query issue, you have errors in the query. Change it like this and try:
pawn Code:
UPDATE `Accounts` SET `adminLevel` = %d, `Money` = %d, `Level` = %d, `LastOn` = %d, `Health` = %f, `Armour` = %f, `Skin` = %d, `Gender` = '%s', `LastIP` = '%s', `Age` = %d WHERE `Username` = '%s'
If there aren't any other errors I haven't noticed, it should work fine.
You also don't need the string size of 9999 for this. 256 will be just fine.
Re: Mysql Saving Data -
Stefand - 07.05.2013
Quote:
Originally Posted by Pooh7
You probably don't get any errors because you haven't enabled MySQL logging.
Add the following line right above your mysql_connect function:
pawn Code:
mysql_log(LOG_ERROR | LOG_WARNING);
As regards the query issue, you have errors in the query. Change it like this and try:
pawn Code:
UPDATE `Accounts` SET `adminLevel` = %d, `Money` = %d, `Level` = %d, `LastOn` = %d, `Health` = %f, `Armour` = %f, `Skin` = %d, `Gender` = '%s', `LastIP` = '%s', `Age` = %d WHERE `Username` = '%s'
If there aren't any other errors I haven't noticed, it should work fine.
You also don't need the string size of 9999 for this. 256 will be just fine.
|
Code:
C:\Users\Stefan Laptop\Desktop\GTA RP Script\gamemodes\roleplay.pwn(160) : error 017: undefined symbol "mysql_log"
Re: Mysql Saving Data -
Stefand - 07.05.2013
Update: Still not saving with the solution from Pooh7
Re: Mysql Saving Data -
Stefand - 07.05.2013
Update: WOW IM STUPID
pawn Code:
if(Authenticated[playerid])
I did not define to check if its true ;S
Changed it to:
pawn Code:
if(Authenticated[playerid] == true)
And its saving now :P
Re: Mysql Saving Data -
PaulDinam - 07.05.2013
Quote:
Originally Posted by Stefand
Update: WOW IM STUPID
pawn Code:
if(Authenticated[playerid])
I did not define to check if its true ;S
Changed it to:
pawn Code:
if(Authenticated[playerid] == true)
And its saving now :P
|
If Authenticated is a bool variable then it doesn't matter if you do == true or without == true.
Re: Mysql Saving Data -
Stefand - 07.05.2013
Quote:
Originally Posted by PaulDinam
If Authenticated is a bool variable then it doesn't matter if you do == true or without == true.
|
it was a bool but it didn't save, and when I changed it to 0 and 1 instead of true and false, it worked