MySQL query leads to crash sometimes!
#1

Well hello again!
My server crash sometimes when a user do the command /vipname.
PHP код:
CMD:vipname(playeridparams[])
{
    new 
text[6], szMessage[256];
    new 
vehicleid GetPlayerVehicleID(playerid);
    if(
sscanf(params"s[50]"text)) return SCM(playeridCOLOR_WHITE"SYNTAX: /vipname [name]");
    if(
PlayerInfo[playerid][pPremiumAccount] != 1) return SCM(playeridCOLOR_ERROR"You don't have a premium account");
    {
        if(
vText[playerid] != -1) return SCM(playeridCOLOR_WHITE"Use first /removename to put another name on your car.");
        if(
GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playeridCOLOR_WHITE"You aren't in any car.");
        if(
GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return SCM(playeridCOLOR_ERROR"You aren't the driver.");
        if(
GetVehicleModel(GetPlayerVehicleID(playerid)) != 411) return SCM(playeridCOLOR_ERROR"Car must be an Infernus in order to apply this command.");
        if(
OwnedVeh(vehicleid))
        {
            
vText[playerid] = CreateObject(19327, -2597.0762, -2638.4270, -5.3536, -87.699990.4001, -87.1805);
            
SetObjectMaterialText(vText[playerid] , text050"Arial"1510xFFFFFFFF01);
            
AttachObjectToVehicle(vText[playerid] , vehicleid0.0,-1.90.3270.00.00.0);
            
format(szMessagesizeof(szMessage), "{F2CF09}Vipname is: '%s'"text);
            
SCM(playeridCOLOR_YELLOWszMessage);
            new var[
64];
            
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'"textPlayerInfo[playerid][pNormalName]);
            
mysql_tquery(SQL, var,"","");
        }
    }
    return 
1;

Also , i can't make a query to load the vipnameinf OnPlayerLogin . :/
Using MySQL R34.
Reply
#2

Below posts got it right.
Reply
#3

Increase the text size to 50, You have defined it as 6 and 50 in the sscanf check, I'm not sure if this is the issue but you should fix that.

PHP код:
new text[50];
if(
sscanf(params"s[50]"text)) return ... 
EDIT:

PHP код:
UPDATE `usersSET `vipnameinf`='%s' WHERE `name`='%d' 
the 'name' column is a string? If so change it to `name`='%s'
Reply
#4

As said above ^

pawn Код:
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'", text, PlayerInfo[playerid][pNormalName]);
You're attempting to save a player name as %d when it needs to be saved as a string. %d treats it as if it was an integer.

Integer = whole number
String = characters

However I'm not sure if that would cause the crash, but it could be.

The fixed version would be;
pawn Код:
mysql_format(SQL, var, sizeof(var),"UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%s'", text, PlayerInfo[playerid][pNormalName]);
Reply
#5

so %d used for a number , not string? if so, why it is working sometimes?
Reply
#6

%d is for integers, i don't really know why it sometimes works for you but the string is %s
If you use %d it would give some random numbers
Reply
#7

Quote:

UPDATE `users` SET `vipnameinf`='%s' WHERE `name`='%d'

Integers dont need ' '
Reply
#8

i will try it 6~9 times and see if crash now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)