[MySQL] Saving User Problem
#1

Hello people. I have, somehow, weird problem. Yesterday my script worked perfectly, everything was saved correctly etc. Now when I have added some additional rows to save in it doesn't work.

This is code:
pawn Код:
stock SaveUser(playerid)
{
    if(Info[playerid][logged] == 1)
    {
        if(Info[playerid][Duty] != -1) Info[playerid][Duty] = 1;
        new string[1024];
        if(IsPlayerRegisteredOnMySQL(PlayerName(playerid)))
        {
            format(string, sizeof(string), "UPDATE 'Users' SET 'Logged' = '0', 'Level' = '%d', 'Kills' = '%d', 'Deaths' = '%d', 'Money' = '%d', 'Score' = '%d', 'Jailed' = '%d', 'LastIP' = '%s', 'Status' = '%d' WHERE 'Username' = '%s' LIMIT 1",Info[playerid][AdminLevel],Info[playerid][Kills],
            Info[playerid][Deaths],GetPVarInt(playerid,"Money"),GetPlayerScore(playerid),Info[playerid][Jailed],PlayerIP(playerid),Info[playerid][Status],PlayerName(playerid));
            mysql_query(string);
            format(string, sizeof(string), "UPDATE 'Users' SET 'vip' = '%d', 'vipTime' = '%d', 'Warning' = '%d', 'Duty' = '%d', 'First' = '%d', 'Second' = '%d', 'Third' = '%d', 'Rules' = '%d' WHERE `Username` = '%s' LIMIT 1",Info[playerid][VIP],Info[playerid][VIPTime],Info[playerid][Warning],
            Info[playerid][Duty],Info[playerid][First],Info[playerid][Second],Info[playerid][Third],Info[playerid][Rules],PlayerName(playerid));
            mysql_query(string);
        }
        else
        {
            format(string, sizeof(string), "/Users/%s.txt", PlayerName(playerid));
            dini_Set(string,"LastIP",PlayerIP(playerid));
            dini_IntSet(string,"Logged",Info[playerid][logged]);
            dini_IntSet(string,"Level",Info[playerid][AdminLevel]);
            dini_IntSet(string,"Kills",Info[playerid][Kills]);
            dini_IntSet(string,"Deaths",Info[playerid][Deaths]);
            dini_IntSet(string,"Money",Info[playerid][Money]);
            dini_IntSet(string,"Score",GetPlayerScore(playerid));
            dini_IntSet(string,"Jailed",Info[playerid][Jailed]);
            dini_IntSet(string,"Status",Info[playerid][Status]);
            dini_IntSet(string,"vip",Info[playerid][VIP]);
            dini_IntSet(string,"vipTime",Info[playerid][VIPTime]);
            dini_IntSet(string,"Warning",Info[playerid][Warning]);
            dini_IntSet(string,"Duty",Info[playerid][Duty]);
            dini_IntSet(string,"First",Info[playerid][First]);
            dini_IntSet(string,"Second",Info[playerid][Second]);
            dini_IntSet(string,"Third",Info[playerid][Third]);
            dini_IntSet(string,"Rules,",Info[playerid][Rules]);
        }
    }
    return true;
}
Those self callbacks are good. it compiles without errors. I searched MySQL's logs and I found this
Код:
[16:08:12] CMySQLHandler::Query(UPDATE 'Users' SET 'Logged' = '0', 'Level' = '5', 'Kills' = '379', 'Deaths' = '170', 'Money' = '33700', 'Score' = '124', 'Jailed' = '0', 'LastIP' = '178.148.226.235', 'Status' = '1' WHERE 'Username' = '[MG]Dimi' LIMIT 1) - An error has occured. (Error ID: 1064, 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 ''Users' SET 'Logged' = '0', 'Level' = '5', 'Kills' = '379', 'Deaths' = '170', 'M' at line 1)
[16:08:12] >> mysql_query( Connection handle: 1 )
[16:08:12] CMySQLHandler::Query(UPDATE 'Users' SET 'vip' = '0', 'vipTime' = '0', 'Warning' = '0', 'Duty' = '-1', 'First' = '1', 'Second' = '0', 'Third' = '0', 'Rules' = '0' WHERE `Username` = '[MG]Dimi' LIMIT 1) - An error has occured. (Error ID: 1064, 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 ''Users' SET 'vip' = '0', 'vipTime' = '0', 'Warning' = '0', 'Duty' = '-1', 'First' at line 1)
Any help? If you have any other questions or needs to fix this just ask and don't say " Use Search" .
Reply
#2

There are not meant to be ' around field names, numerical values or table names.
Reply
#3

I tried without it also. Same thing.
Reply
#4

Remove LIMIT 1 at the end and try.

PHP код:
UPDATE `UsersSET Logged '0'Level = %dKills = %dDeaths = %dMoney = %dScore = %dJailed = %dLastIP = %sStatus = %d WHERE Username '%s' 
Reply
#5

Код:
UPDATE `Users` SET `vip` = '0', `vipTime` = '0', `Warning` = '0', `Duty` = '-1', `First` = '1', `Second` = '0', `Third` = '0', `Rules` = '0' WHERE `Username` = '%s' LIMIT 1;
You should use ` ` around your field, table and database names and ' ' around values.
Reply
#6

Quote:
Originally Posted by XFlawless
Посмотреть сообщение
Remove LIMIT 1 at the end and try.

PHP код:
UPDATE `UsersSET Logged '0'Level = %dKills = %dDeaths = %dMoney = %dScore = %dJailed = %dLastIP = %sStatus = %d WHERE Username '%s' 
Wouldn't that just allow him to change in multiple lines if there is given username? Anyway I will try but I doubt.
Reply
#7

Try with:

PHP код:
UPDATE `UsersSET `Logged` = 0, `Level` = %d, `Kills` = %d, `Deaths` = %d, `Money` = %d, `Score` = %d, `Jailed` = %d, `LastIP` = '%s', `Status` = %d WHERE `Username` = '%s' LIMIT 1
' ' should be used for strings only, `` for table and row names (Optional AFAIK), and for numerical values there is no need of adding anything
Reply
#8

Nope. Same thing.
Reply
#9

When you enter string you need '' but numbers is not needed...
Reply
#10

Nope. I actually fixed problem. While I was scripting this I was in hurry. Problem is you can put values inside ' ' but Tables and Columns must be inside Grave ` `. I was in hurry so I put everything between ' '. Thanks everyone who tried to help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)