SA-MP Forums Archive
Mysql problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Mysql problem (/showthread.php?tid=624055)



Mysql problem - bugmenotlol - 10.12.2016

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
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(Querysizeof(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(); 



Re: Mysql problem - bugmenotlol - 10.12.2016

bump


Re: Mysql problem - bugmenotlol - 10.12.2016

Anyone plz


Re: Mysql problem - iLearner - 10.12.2016

stop using mysql_reconnect();