Save into MYSQL
#1

I trying to make a function that will switch the data in fields.
pawn Код:
new sscanfinput[64], string[128];
            new name[24],
            Escape[2][128];
            GetPlayerName(playerid, name, 24);
            mysql_real_escape_string(name, Escape[0]); // This function makes sure you don't get MySQL injected. Read about it by searching it on ******.
            format(string, 128, "SELECT * FROM `playerinfo` WHERE user = '%s'", Escape[0]);
            mysql_query(string);
            new Query[1024];
            new Query2[1024];
            new Query3[1024];
format(Query, sizeof(Query), "UPDATE `playerinfo` SET `key` = '%s' WHERE `user` = '%s'", PlayerInfo[playerid][pKey], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `level` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pLevel], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `admin` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pAdmin], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `donaterank` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pDonateRank], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `upgradepoints` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][gPupgrade],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `connectedtime` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pConnectTime],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `sex` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pSex],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `age` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pAge],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `ck` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pCK],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `muted` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pMuted],  Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `respect` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pExp], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `money` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pCash], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `ban` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pBan], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `reason` = '%s' WHERE `user` = '%s'", PlayerInfo[playerid][pReason], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `bank` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pAccount], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `crimes` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pCrimes], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `deaths` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pDeaths], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `kills` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pKills], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `arrested` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pArrested], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `wanteddeaths` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pWantedDeaths], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `phonebook` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pPhoneBook], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `job` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJob], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `paycheck` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pPayCheck], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailed` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailed], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailtime` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailTime], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailday` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailday], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailmonth` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailmonth], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailyear` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailyear], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `jailar` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pJailar], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `materials` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pMats], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `drugs` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pDrugs], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `leader` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pLeader], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `member` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pMember], Escape[0]);
            mysql_query(Query);
            format(Query, sizeof(Query), "UPDATE `playerinfo` SET `fmember` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pFMember], Escape[0]);
            mysql_query(Query);
mysql_free_result();
            return 1;
This code not working at all.
Reply
#2

Maybe you can check the CWRP. this is a Full SQL GM.
Reply
#3

Is there a entry in your Database yet? If not you cannot use UPDATE, you need to use INSERT in that case.
Also you could make it more effecient by not always formating the string. Use this:
Код:
UPDATE `playerinfo` SET (`member`,`blabla`,`Blabla2`) VALUES ('%d','%d','%d') WHERE `user` = '%s'
I'm not 100% sure if this works, but i think so.

#edit: i corrected my post
Reply
#4

What wrong with my code? thats UPDATE too.
And i have already the fields.
Reply
#5

Quote:
Originally Posted by vection
Посмотреть сообщение
What wrong with my code? thats UPDATE too.
And i have already the fields.
What does the SQL log say?
Reply
#6

Where i can find the Database log?
Reply
#7

upppppppppppppp
Reply
#8

I fixed it.
Reply
#9

Quote:
Originally Posted by DeathOnaStick
Посмотреть сообщение
Is there a entry in your Database yet? If not you cannot use UPDATE, you need to use INSERT in that case.
Also you could make it more effecient by not always formating the string. Use this:
Код:
UPDATE `playerinfo` SET (`member`,`blabla`,`Blabla2`) VALUES ('%d','%d','%d') WHERE `user` = '%s'
I'm not 100% sure if this works, but i think so.

#edit: i corrected my post
I use this:
Код:
UPDATE `playerinfo` SET `key` = '%s', `level` = '%d',`admin` = '%d' WHERE `user` = '%s'", PlayerInfo[playerid][pKey], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], Escape[0]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)