18.07.2015, 09:23
PHP Code:
stock MySQL_Login(playerid)
{
new Query[500];
mysql_real_escape_string(pInfo[playerid][Nick], pInfo[playerid][Nick]); // escaping the name of the player to avoid sql_injections.
format(Query, sizeof(Query), "SELECT * FROM `playerdata` WHERE `nick` COLLATE latin1_general_cs = '%s' LIMIT 1", pInfo[playerid][Nick]);
mysql_query(Query);
mysql_store_result();
while(mysql_fetch_row(Query))
{
mysql_fetch_int("id", pInfo[playerid][ID]);
mysql_fetch_int("admin", pInfo[playerid][pAdmin]);
mysql_fetch_int("helper", pInfo[playerid][pHelper]);
mysql_fetch_int("moderator", pInfo[playerid][pMod]);
mysql_fetch_int("score", pInfo[playerid][pScore]); SetPlayerScore(playerid, pInfo[playerid][pScore]);
mysql_fetch_int("money", pInfo[playerid][pMoney]); GivePlayerMoney(playerid, pInfo[playerid][pMoney]);
mysql_fetch_int("gold", pInfo[playerid][Gold]);
mysql_fetch_int("kills", pInfo[playerid][pKills]);
mysql_fetch_int("deaths", pInfo[playerid][pDeaths]);
mysql_fetch_int("PosX", pInfo[playerid][PosX]);
mysql_fetch_int("PosY", pInfo[playerid][PosY]);
mysql_fetch_int("PosZ", pInfo[playerid][PosZ]);
mysql_fetch_int("kicks", pInfo[playerid][kicks]);
mysql_fetch_int("bans", pInfo[playerid][bans]);
mysql_fetch_int("banned", pInfo[playerid][pBanned]);
mysql_fetch_int("playinghours", pInfo[playerid][PlayingHours]);
mysql_fetch_int("adminhelp", pInfo[playerid][AdminHelp]);
mysql_fetch_int("experiencepoints", pInfo[playerid][ExperiencePoints]);
mysql_fetch_int("experiencepointsneeded", pInfo[playerid][ExperiencePointsNeeded]);
mysql_fetch_int("secondslogged", pInfo[playerid][SecondsLoggedIn]);
}
mysql_free_result();
// here we free our result and end the SELECT process.
pInfo[playerid][Logged] = 1; // sets the logged variable to 1 meaning logged in.
return 1;
}
SavePlayer(playerid)
{
if(pInfo[playerid][Logged] == 1)
{
new Query[500];
format(Query, 500, "UPDATE `playerdata` SET `admin` = %d, `helper` = %d, `moderator` = %d, `score` = %d, `money` = %d, `kills` = %d, `deaths` = %d, `experiencepoints` = %d, `experiencepointsneeded` = %d, `PosX` = %d, `PosZ` = %d, `PosY` = %d, `kicks` = %d, `bans` = %d, `banned` = %d, `playinghours`= %d, `secondslogged` = %d, `adminhelp` = %d, WHERE `id` = %d",
pInfo[playerid][pAdmin],
pInfo[playerid][pHelper],
pInfo[playerid][pMod],
pInfo[playerid][pScore],
pInfo[playerid][pMoney],
pInfo[playerid][pKills],
pInfo[playerid][pDeaths],
pInfo[playerid][ExperiencePoints],
pInfo[playerid][ExperiencePointsNeeded],
pInfo[playerid][PosX],
pInfo[playerid][PosZ],
pInfo[playerid][PosY],
pInfo[playerid][kicks],
pInfo[playerid][bans],
pInfo[playerid][pBanned],
pInfo[playerid][PlayingHours],
pInfo[playerid][SecondsLoggedIn],
pInfo[playerid][AdminHelp],
pInfo[playerid][ID]);
mysql_query(Query);
}
}
pawn Code:
[02:43:34] [MySQL] Error (0): Failed to exeute query. Column count doesn't match value count at row 1.
[02:43:42] [MySQL] Error (0): Failed to exeute query. 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 'WHERE `id` = 0' at line 1.
PHP Code:
CREATE TABLE IF NOT EXISTS `playerdata` (
`nick` varchar(255) NOT NULL,
`password` varchar(255) NOT NULL,
`ip` varchar(15) NOT NULL,
`admin` int(10) NOT NULL DEFAULT '0',
`helper` int(10) NOT NULL DEFAULT '0',
`moderator` int(10) NOT NULL DEFAULT '0',
`score` int(15) NOT NULL DEFAULT '0',
`money` int(15) NOT NULL DEFAULT '0',
`kills` int(15) NOT NULL DEFAULT '0',
`deaths` int(15) NOT NULL DEFAULT '0',
`experiencepoints` int(15) NOT NULL DEFAULT '0',
`experiencepointsneeded` int(15) NOT NULL DEFAULT '0',
`PosX` float NOT NULL,
`PosZ` float NOT NULL,
`PosY` float NOT NULL,
`kicks` int(15) NOT NULL DEFAULT '0',
`bans` int(15) NOT NULL DEFAULT '0',
`banned` int(15) NOT NULL DEFAULT '0',
`playinghours` int(15) NOT NULL DEFAULT '0',
`secondslogged` varchar(15) NOT NULL DEFAULT '0',
`adminhelp` int(15) NOT NULL DEFAULT '0',
`id` int(15) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;