PDA

View Full Version : Help with MySQL


Sreadon
06/10/2011, 09:17 PM
Hello,

Firsly, I'm a totaly newbie with MySQL, so don't blame me please. I try to learn MySQL to link a futur UCP and my gamemode, so, to test some functions, I've try to do this:


#define SQL_HOST "localhost"
#define SQL_DB "sforp"
#define SQL_USER "root"
#define SQL_PASS ""

if(strcmp(cmd, "/actualise", true) == 0)
{
MySaveAccount(playerid);
return 1;
}



stock MySaveAccount(playerid)
{
new string[1024];
if(IsPlayerConnected(playerid))
{
new pName[MAX_PLAYERS];
GetPlayerName(playerid,pName,sizeof(pName));
format(string, sizeof(string), "UPDATE `utilisateurs` SET `Level` = '%d', `AdminLevel` = '%d', `DonateRank` = '%d', `UpgradePoints` = '%d',`Connectedtime` = '%d' WHERE `Pseudo` = '%d'", PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][gPupgrade], PlayerInfo[pConnectTime], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `Registered` = '%d', `Sex = '%d', `Age` = '%d', `Origin = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pReg], PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pOrigin], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `CK` = '%d', `Muted` = '%d', `MutedOOC` = '%d', `Respect` = '%d',`Money` = '%d',`Bank` = '%d',`Crimes` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pCK], PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pMutedOOC], PlayerInfo[playerid][pExp], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pAccount], PlayerInfo[playerid][pCrimes], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `Kills` = '%d', `Deaths` = '%d', `Arrested` = '%d', `WantedDeaths` = '%d', `Phonebook` = '%d', `LottoNr` = '%d', `Fishes` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pKills],PlayerInfo[playerid][pDeaths], PlayerInfo[playerid][pArrested], PlayerInfo[playerid][pWantedDeaths], PlayerInfo[playerid][pPhoneBook], PlayerInfo[playerid][pLottoNr], PlayerInfo[playerid][pFishes], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `BiggestFish` = '%f', `Job` = '%d', `PayCheck` = '%d', `HeadValue` = '%d', `Jailed` = '%d', `JailTime` = '%d', `Materials` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pBiggestFish], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pPayCheck], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pMats], PlayerInfo[playerid][pMatsf], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `Materialssf` = '%d', `Drugs` = '%d', `Leader` = '%d', `Member` = '%d', `FMember` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pMatsf],PlayerInfo[playerid][pDrugs], PlayerInfo[playerid][pLeader], PlayerInfo[playerid][pMember], PlayerInfo[playerid][pFMember], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `Rank` = '%d', `Char` = '%d', `ContractTime` = '%d', `DetSkill` = '%d', `SexSkill` = '%d', `BoxSkill` = '%d', `LawSkill` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pRank],PlayerInfo[playerid][pChar], PlayerInfo[playerid][pContractTime], PlayerInfo[playerid][pDetSkill], PlayerInfo[playerid][pSexSkill], PlayerInfo[playerid][pBoxSkill], PlayerInfo[playerid][pLawSkill], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `MechSkill` = '%d', `JackSkill` = '%d', `CarSkill` = '%d', `NewsSkill` = '%d', `DrugsSkill` = '%d', `CookSkill` = '%d', `FishSkill` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pMechSkill],PlayerInfo[playerid][pJackSkill], PlayerInfo[playerid][pCarSkill], PlayerInfo[playerid][pNewsSkill], PlayerInfo[playerid][pDrugsSkill], PlayerInfo[playerid][pCookSkill], PlayerInfo[playerid][pFishSkill], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `pSHealth` = '%d', `pHealth` = '%d', `Int` = '%d', `Local` = '%d', `Team` = '%d', `Model` = '%d', `PhoneNr` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pSHealth],PlayerInfo[playerid][pHealth], PlayerInfo[playerid][pInt], PlayerInfo[playerid][pLocal], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pModel], PlayerInfo[playerid][pPnumber], pName);
mysql_query(string);

format(string, sizeof(string), "UPDATE `utilisateurs` SET `Car` = '%d', `Car2` = '%d', `Car3` = '%d', `House` = '%d', `Bizz` = '%d', `Pos_x` = '%d', `Pos_y`, `Pos_z` = '%d' WHERE `pseudo` = '%d'", PlayerInfo[playerid][pPcarkey],PlayerInfo[playerid][pPcarkey2], PlayerInfo[playerid][pPcarkey3], PlayerInfo[playerid][pPhousekey], PlayerInfo[playerid][pPbiskey], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], pName);
mysql_query(string);

// And other stuff here, same as before.
}


return 1;
}



I've already created the database on phpmyadmin, and wampserver is ON. I go in game and type /actualise but nothing actualise on phpmyadmin, values stays to 0, exept password and user, because I've manualy define them.

Thanks for your help, and I don't ask a script, I've just want to learn where is my error, and how to fix it..

PS:
I use BlueG's MySQL plugin who can be find at : http://forum.sa-mp.com/showthread.php?t=56564

kirk
07/10/2011, 12:13 AM
WHERE `Pseudo` = '%d'

Its a name so '%s' as its an string, i guess you should check the difference between integers, float numbers and strings, aswell fix it on your database, it should be text or varchar(24) ( for the name).

Dont use ' ' for the integers do it only for strings, so it should be %d or %i instead of '%d'

btw

Float numbers 233.2123 (example) as %f
Character strings " Hello World!! " (example) as '%s', or '%e' if you wanna escape it using mysql_format(); instead of format();
and integers 1 or 98765 or 1983489 or 0 (examples) as %d or %i.

Sreadon
07/10/2011, 04:15 PM
Okay thanks, but don't work.. I've do this:


stock MySaveAccount(playerid)
{
new string[1024];
if(IsPlayerConnected(playerid))
{
new pName[MAX_PLAYERS];
GetPlayerName(playerid,pName,sizeof(pName));
format(string, sizeof(string), "UPDATE `utilisateurs` SET `Level` =%d, `AdminLevel` =%d, `DonateRank` =%d, `UpgradePoints` =%d,`Connectedtime` =%d WHERE `Pseudo` = '%s'", PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pDonateRank], PlayerInfo[playerid][gPupgrade], PlayerInfo[pConnectTime], pName);
mysql_query(string);

}
return 1;
}

I'm wrong somewhere?

kirk
09/10/2011, 09:07 PM
Enable the debug file and post the error line.