10.12.2016, 06:04
hi i have a issue with mysql database.
when a player enter first time it should insert values to db then second time it should load but the problem is it is creating multiple rows or registering again and again to db..
here is the code
when a player enter first time it should insert values to db then second time it should load but the problem is it is creating multiple rows or registering again and again to db..
here is the code
PHP код:
new Query[80], pName[MAX_PLAYER_NAME];
GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
format(Query,sizeof(Query),"SELECT `nicknames` FROM `xmas` WHERE `nicknames` = '%s' LIMIT 1;",pName);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
mysql_reconnect();
new Query[156], EscName[MAX_PLAYER_NAME];
mysql_real_escape_string(PlayerName(playerid), EscName);
//mysql_reconnect();
format(Query, sizeof(Query), "SELECT * FROM `xmas` WHERE `nicknames` = '%s'", EscName);
mysql_query(Query);
mysql_store_result();
new resultline[200];
if (mysql_fetch_row(resultline))
{
sscanf(resultline,"p<|>s[120]ddddddddddddddddddddd",PlayerName(playerid),XInfo[playerid][pGiftTaken1],XInfo[playerid][pGiftTaken2],XInfo[playerid][pGiftTaken3],XInfo[playerid][pGiftTaken4],XInfo[playerid][pGiftTaken5],XInfo[playerid][pGiftTaken6],XInfo[playerid][pGiftTaken7],XInfo[playerid][pGiftTaken8],XInfo[playerid][pGiftTaken9],XInfo[playerid][pGiftTaken10],
XInfo[playerid][pGiftTaken11],XInfo[playerid][pGiftTaken12],XInfo[playerid][pGiftTaken13],XInfo[playerid][pGiftTaken14],XInfo[playerid][pGiftTaken15],XInfo[playerid][pGiftTaken16],XInfo[playerid][pGiftTaken17],XInfo[playerid][pGiftTaken18],XInfo[playerid][pGiftTaken19],XInfo[playerid][pGiftTaken20],XInfo[playerid][Eventfinished]);
SendClientMessage(playerid,COLOR_ERROR,"Event stats loaded.");
}
mysql_free_result();
}
else
{
mysql_reconnect();
new query[650];
format(query,sizeof(query),"INSERT INTO `xmas` (nicknames, pGiftTaken1,pGiftTaken2,pGiftTaken3,pGiftTaken4,pGiftTaken5,pGiftTaken6,pGiftTaken7,pGiftTaken8,pGiftTaken9,pGiftTaken10,pGiftTaken11,pGiftTaken12,pGiftTaken13,pGiftTaken14,pGiftTaken15,pGiftTaken16,pGiftTaken17,pGiftTaken18,pGiftTaken19,pGiftTaken20,Eventfinished) VALUES ('%s', '%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')"
,PlayerName(playerid),0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
mysql_reconnect();
mysql_query(query);
SendClientMessage(playerid,COLOR_ERROR,"registered for event.");
}
mysql_free_result();