Mysql Saving Data
#1

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.
Reply
#2

Quote:
Originally Posted by Stefand
View Post
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.
Reply
#3

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.
Reply
#4

Quote:
Originally Posted by Pooh7
View Post
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"
Reply
#5

Update: Still not saving with the solution from Pooh7
Reply
#6

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
Reply
#7

Quote:
Originally Posted by Stefand
View Post
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.
Reply
#8

Quote:
Originally Posted by PaulDinam
View Post
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)