SA-MP Forums Archive
mysql saving - 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 saving (/showthread.php?tid=597160)



mysql saving - AndreiWow - 27.12.2015

Код:
case DIALOG_FORUMNAME:
  		{
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_FORUMNAME , DIALOG_STYLE_INPUT, "Forumname", "Te rugam introdu-ti numele de pe forum mai jos.", "Enter", "Cancel");
                new string[64];
                
                GetPlayerName(playerid, szPlayerName, MAX_PLAYER_NAME);
				mysql_real_escape_string(szPlayerName, szPlayerName);

				format(szLargeString, sizeof(szLargeString), "INSERT INTO playeraccounts (forumname) VALUES('%s')", inputtext);
				mysql_tquery(handle, szLargeString);
				SCM(playerid, COLOR_GREEN, "Ti-ai setat forumname-ul.");
            }
		}
This is the dialog for /forumname but if he use it again it will add another row?
How to make to update the actual row if he already set his username?


Re: mysql saving - Boar - 27.12.2015

What do you store in the table "playeraccounts"?


Re: mysql saving - zPain - 27.12.2015

http://dev.mysql.com/doc/refman/5.7/en/update.html


Re: mysql saving - ikey07 - 27.12.2015

format(szLargeString, sizeof(szLargeString), "UPDATE `playeraccounts` SET `forumname` = '%s' WHERE `playername` = '%s'", szPlayerName,name);

Use UPDATE function.
Also see where I set bold, NEVER forget to use mysql_real_escape_string made string in the queries.