MySQL does not save, been searching for hours.
#1

What's going on? I've made it the exact same way as my userdata, vehicledata and businessdata but my houses aren't saving!

They do get created, but whenever I buy them the variable doesnt save

pawn Код:
forward SaveHouses2(i);
public SaveHouses2(i)
{
    new query[1500];
    format(query, sizeof(query), "UPDATE housedata SET HouseOwner=%d,HouseX=%f,HouseY=%f,HouseZ=%f WHERE HouseID=%i",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
    mysql_function_query(ServerInfo[MySQL], query, true, "Something", "i",i);
    format(query, sizeof(query), "UPDATE housedata SET HouseX2=%f, HouseY2=%f, HouseZ2=%f,HousePrice=%i WHERE HouseID=%i",Housee[i][HouseOwner],Housee[i][HouseX2],Housee[i][HouseY2],Housee[i][HouseZ2],Housee[i][HousePrice], i);
    mysql_function_query(ServerInfo[MySQL], query, true, "Something", "i",i);
    format(query, sizeof(query), "UPDATE housedata SET HouseInt=%d, HouseWep=%d,HouseWepAmmo=%d,HouseMats=%d WHERE HouseID=%i",Housee[i][HouseInt],Housee[i][HouseWep],Housee[i][HouseWepAmmo],Housee[i][HouseMats], i);
    mysql_function_query(ServerInfo[MySQL], query, true, "Something", "i",i);
    format(query, sizeof(query), "UPDATE housedata SET HouseHeroin=%d,HouseLocked=%d,HouseOwnerName='%s' WHERE HouseID=%i",Housee[i][HouseHeroin], Housee[i][HouseLocked],Housee[i][HouseLocked],Housee[i][HouseOwnerName], i);
    mysql_function_query(ServerInfo[MySQL], query, true, "Something", "i",i);
    return 1;
}
And this is part of /buyhouse

pawn Код:
if(IsPlayerInRangeOfPoint(playerid, 1.5,Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ]))
        {
            if(PlayerInfo[playerid][Cash] < Housee[i][HousePrice]) return error(playerid, "You do not have enough money.");
            if(PlayerInfo[playerid][House] != 0) return error(playerid, "You already own a property.");
            if(Housee[i][HouseOwner] != 0) return error(playerid, "This house is not for sale.");
            Housee[i][HouseOwner] = PlayerInfo[playerid][UserId];
            new stringg[24];
            format(stringg, sizeof(stringg), "%s",GetNameEx(playerid));
            Housee[i][HouseOwnerName] = stringg;
            PlayerInfo[playerid][House] = i;
            GivePlayerCash(playerid, -Housee[i][HousePrice]);
            new string[128];
            format(string, sizeof(string), "{6B5BBD}[{5BBD8A}Owned House{6B5BBD}]\n{6B5BBD}[{5BBD8A} Owner: %s{6B5BBD}]",Housee[i][HouseOwnerName]);
            Update3DTextLabelText(HouseText[i], red, string);
            SaveHouses2(i);
            return 1;
        }
It all works ingame, and I can exit/enter/lock/store etc everything with the house, but the variable won't save in the SQL database!

Screenshot in the attachment


I have no idea what's going on to be honest, everything else saves perfectly fine.
Reply
#2

Where are the '' on the %s , %f ?
Reply
#3

Quote:
Originally Posted by next-studio|TheKiller
Посмотреть сообщение
Where are the '' on the %s , %f ?
There is no section with a float followed by a string, so show me what yo mean.
Reply
#4

Quote:
Originally Posted by milanosie
Посмотреть сообщение
There is no section with a float followed by a string, so show me what yo mean.
What i mean is:
pawn Код:
format(query, sizeof(query), "UPDATE housedata SET HouseOwner=%d,HouseX=%f,HouseY=%f,HouseZ=%f WHERE HouseID=%i",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
Change for
pawn Код:
format(query, sizeof(query), "UPDATE housedata SET HouseOwner = '%d', HouseX = '%f' ,HouseY = '%f' ,HouseZ = '%f'  WHERE HouseID = '%i'",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
Reply
#5

Quote:
Originally Posted by next-studio|TheKiller
Посмотреть сообщение
What i mean is:
pawn Код:
format(query, sizeof(query), "UPDATE housedata SET HouseOwner=%d,HouseX=%f,HouseY=%f,HouseZ=%f WHERE HouseID=%i",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
Change for
pawn Код:
format(query, sizeof(query), "UPDATE housedata SET HouseOwner = '%d', HouseX = '%f' ,HouseY = '%f' ,HouseZ = '%f'  WHERE HouseID = '%i'",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
That's absolutly not neccasary
So no, I'm not going to change it into that.

The ' ' is only needed on a string value
Reply
#6

Quote:
Originally Posted by milanosie
Посмотреть сообщение
That's absolutly not neccasary
So no, I'm not going to change it into that.

The ' ' is only needed on a string value
For float, you need it.
And you can use on all, it isn't going to slow down anything.
If you don't try, you don't know.

or enable mysql debugging and see what's going on.
Reply
#7

Try disable cache. Not necessary for update queries.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Try disable cache. Not necessary for update queries.
Like this hmm?
pawn Код:
format(query, sizeof(query), "UPDATE housedata SET HouseOwner=%d,HouseX=%f,HouseY=%f,HouseZ=%f WHERE HouseID=%i",Housee[i][HouseOwner],Housee[i][HouseX],Housee[i][HouseY],Housee[i][HouseZ], i);
        mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
        format(query, sizeof(query), "UPDATE housedata SET HouseX2=%f, Housey2=%f, Housez2=%f,HousePrice=%i WHERE HouseID=%i",Housee[i][HouseX2],Housee[i][HouseY2],Housee[i][HouseZ2],Housee[i][HousePrice], i);
        mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
        format(query, sizeof(query), "UPDATE housedata SET HouseInt=%d, HouseWep=%d,HouseWepAmmo=%d,HouseMats=%d WHERE HouseID=%i",Housee[i][HouseInt],Housee[i][HouseWep],Housee[i][HouseWepAmmo],Housee[i][HouseMats], i);
        mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
        format(query, sizeof(query), "UPDATE housedata SET HouseHeroin=%d,HouseLocked=%d,HouseOwnerName='%s' WHERE HouseID=%i",Housee[i][HouseHeroin], Housee[i][HouseLocked],Housee[i][HouseLocked],Housee[i][HouseOwnerName], i);
        mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
And nope, it still didn't work,

It just doesn't save, no errors in the log or w/e, nothing.
Reply
#9

Off-topic.

That saving function could be optimized. You're using 1500 cells, might as well use it all in one query.
pawn Код:
forward SaveHouses2(i);
public SaveHouses2(i)
{
    new query[1500];
    format(query, sizeof(query), "UPDATE housedata SET \
        HouseOwner = %d, \
        HouseX = %f, \
        HouseY = %f, \
        HouseZ = %f, \
        HouseX2 = %f, \
        HouseY2 = %f, \
        HouseZ2 = %f, \
        HousePrice = %i"
,
        Housee[i][HouseOwner],
        Housee[i][HouseX],
        Housee[i][HouseY],
        Housee[i][HouseZ],
        Housee[i][HouseX2],
        Housee[i][HouseY2],
        Housee[i][HouseZ2],
        Housee[i][HousePrice]      
    );
   
    format(query, sizeof(query), "%s, \
        HouseInt = %d, \
        HouseWep = %d, \
        HouseWepAmmo = %d, \
        HouseMats = %d, \
        HouseHeroin = %d, \
        HouseLocked = %d, \
        HouseOwnerName = '%s', \
        WHERE HouseID = %i"
,
        query,
        Housee[i][HouseInt],
        Housee[i][HouseWep],
        Housee[i][HouseWepAmmo],
        Housee[i][HouseMats],
        Housee[i][HouseHeroin],
        Housee[i][HouseLocked],
        Housee[i][HouseOwnerName],
        i
    );
    mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
    return 1;
}
IMO, that way is much easier to read (everyone is different though), and very practical when you want to go back and make changes. It's also being done in one query, and makes use of the 1500 cells.
Reply
#10

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Off-topic.

That saving function could be optimized. You're using 1500 cells, might as well use it all in one query.
pawn Код:
forward SaveHouses2(i);
public SaveHouses2(i)
{
    new query[1500];
    format(query, sizeof(query), "UPDATE housedata SET \
        HouseOwner = %d, \
        HouseX = %f, \
        HouseY = %f, \
        HouseZ = %f, \
        HouseX2 = %f, \
        HouseY2 = %f, \
        HouseZ2 = %f, \
        HousePrice = %i"
,
        Housee[i][HouseOwner],
        Housee[i][HouseX],
        Housee[i][HouseY],
        Housee[i][HouseZ],
        Housee[i][HouseX2],
        Housee[i][HouseY2],
        Housee[i][HouseZ2],
        Housee[i][HousePrice]      
    );
   
    format(query, sizeof(query), "%s, \
        HouseInt = %d, \
        HouseWep = %d, \
        HouseWepAmmo = %d, \
        HouseMats = %d, \
        HouseHeroin = %d, \
        HouseLocked = %d, \
        HouseOwnerName = '%s', \
        WHERE HouseID = %i"
,
        query,
        Housee[i][HouseInt],
        Housee[i][HouseWep],
        Housee[i][HouseWepAmmo],
        Housee[i][HouseMats],
        Housee[i][HouseHeroin],
        Housee[i][HouseLocked],
        Housee[i][HouseOwnerName],
        i
    );
    mysql_function_query(ServerInfo[MySQL], query, false, "Something", "i",i);
    return 1;
}
IMO, that way is much easier to read (everyone is different though), and very practical when you want to go back and make changes. It's also being done in one query, and makes use of the 1500 cells.
Yeah thanks for the tip, I'm kinda new to SQL, but that still doesn't fix anything.
Any idea what might be the problem ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)