SA-MP Forums Archive
[Tutorial] [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] (/showthread.php?tid=574714)

Pages: 1 2 3


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Denis1 - 15.06.2015

Awesome work!


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Overhaul - 15.06.2015

Quote:
Originally Posted by dudu.r.oliveira
View Post
@EDIT: sorry, i'm a idiot, i was not adding includes only the plugins.
Glad you fixed it.

Quote:
Originally Posted by Denis1
View Post
Awesome work!
Thank you.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - MD5 - 15.06.2015

C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(34 : error 017: undefined symbol "posX"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(34 : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(349) : error 017: undefined symbol "posY"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(349) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(350) : error 017: undefined symbol "posZ"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(350) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(351) : error 017: undefined symbol "posA"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(351) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(353) : error 017: undefined symbol "SetPlayerMoney"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(355) : warning 217: loose indentation
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Overhaul - 15.06.2015

Quote:
Originally Posted by MD5
View Post
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(34 : error 017: undefined symbol "posX"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(34 : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(349) : error 017: undefined symbol "posY"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(349) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(350) : error 017: undefined symbol "posZ"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(350) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(351) : error 017: undefined symbol "posA"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(351) : warning 213: tag mismatch
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(353) : error 017: undefined symbol "SetPlayerMoney"
C:\Users\Jaden\Desktop\SAMP Scripting\gamemodes\lsgw.pwn(355) : warning 217: loose indentation
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
I fixed the mistakes. It was supposed to be 'GivePlayerMoney'. As for the errors related to 'Pos', I had defined them with a capital letter and then used them without a capital letter.
I have updated the code of the the player's enum, OnAccountLoad and OnPlayerSpawn.

Thank you for reporting that back to me.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - sonanclar - 16.06.2015

Thank you for the very interesting information. I’m glad that you simply shared this helpful information with us.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - JaydenJason - 03.07.2015

Somehow "OnAccountCheck" isn't being called for me.

Code:
public OnPlayerConnect(playerid)
{
    printf("OnPlayerConnect begin");
	new query[128];
	PreparePlayerConnection(playerid);
    mysql_format(mysql, query, sizeof(query), "SELECT `pPassword`, `pID` FROM `accs` WHERE `pName` = '%e' LIMIT 1", PlayerName(playerid));
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
    printf("OnPlayerConnect end");
	return 1;
}

forward OnAccountCheck(playerid); public OnAccountCheck(playerid)
{
    printf("OnAccountCheck begin");
    new
        rows,
        fields,
		welcomestr[200];
    cache_get_data(rows, fields, mysql);
    printf("OnAccountCheck get data");
    if(rows)
    {
        printf("OnAccountCheck if rows begin");
        cache_get_field_content(0, "Password", pData[playerid][pPass], mysql, 129);
        pData[playerid][pID] = cache_get_field_content_int(0, "pID");
        format(welcomestr, sizeof(welcomestr), "Welcome %s!\nYour account has been previously registered in our database.\nPlease fill in your password:", GetPlayerForename(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login to MY_TEST_SERVER.", welcomestr, "Login", "Quit");
        printf("OnAccountCheck if rows end");
    }
    else
    {
        printf("OnAccountCheck else begin");
        format(welcomestr, sizeof(welcomestr), "Welcome to MY_TEST_SERVER, %s!\nIt appears that this is your first time playing here!\nPlease fill in your password below\nto register to MY_TEST_SERVER!", GetPlayerForename(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_PASSWORD, "Register to MY_TEST_SERVER.", welcomestr, "Register", "Quit");
        printf("OnAccountCheck else end");
    }
    printf("OnAccountCheck end");
    return 1;
}
Only prints

Code:
OnPlayerConnect begin
OnPlayerConnect end
EDIT: used OnQueryError and printed its results, turns out I had some wrong names for a couple columns! Thanks for the tutorial!


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - AchievementMaster360 - 10.07.2015

Awesome tutorial, thanks for the help.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Overhaul - 10.07.2015

Quote:
Originally Posted by AchievementMaster360
View Post
Awesome tutorial, thanks for the help.
Glad you liked it.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Billeen - 20.07.2015

Hello,

When I register on the server, I appear on Blueberry Farm.

I edited this:

Code:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, this, this, this, this)", playername, Player[playerid][Password], playerip);
But still does not work


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Overhaul - 20.07.2015

Quote:
Originally Posted by Billeen
View Post
Hello,

When I register on the server, I appear on Blueberry Farm.

I edited this:

Code:
mysql_format(mysql, query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, this, this, this, this)", playername, Player[playerid][Password], playerip);
But still does not work
Let us make use of defines to specify the starting point, make sure that after the account is registered, that the new coordinates are updated in the database too (either remove the account or manually edit the values in phpMyAdmin or any other way that you use).

Defines:
PHP Code:
#define SPAWN_X 1.0
#define SPAWN_Y 2.0
#define SPAWN_Z 13.0 // usually the ground level in GTA SA
#define SPAWN_A 90.0 // Facing angle 
And then replace the values to these defines. Like so:
PHP Code:
mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX`, `PosY`, `PosZ`, `PosA`) VALUES ('%e', '%e', '%e', 0, 0, 0, %f, %f, %f, %f)"playernamePlayer[playerid][Password], playeripSPAWN_XSPAWN_YSPAWN_ZSPAWN_A); 



Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - saffierr - 18.03.2016

It somehow refuses to show me any dialog when connecting.
The mysql_log.txt shows this:

Quote:

[14:09:49] [ERROR] mysql_format - invalid connection handle (id: 0)
[14:09:49] [ERROR] mysql_tquery - invalid connection handle (id: 0)
[14:10:01] [ERROR] mysql_format - invalid connection handle (id: 0)
[14:10:01] [ERROR] mysql_tquery - invalid connection handle (id: 0)

Does anyone know what this means?


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - AndySedeyn - 18.03.2016

Quote:
Originally Posted by saffierr
View Post
It somehow refuses to show me any dialog when connecting.
The mysql_log.txt shows this:


Does anyone know what this mean?
Are you correctly connecting to the database before sending queries?


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - saffierr - 18.03.2016

As I am new to this mysql thingy, I can't answer your question, if I would I'd lie anyways.
Anyways, this my onplayerconnect and OnAccountCheck

PHP Code:
public OnPlayerConnect(playerid)
{
    new 
query[128], pName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
    
TogglePlayerSpectating(playerid1);
    
mysql_format(mysqlquerysizeof query"SELECT 'Password', 'ID' FROM 'accounts' WHERE 'Name' = '%e' LIMIT 1"pName);
     
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    
SendClientMessage(playeridCOLOR_GREEN"Awoo welcome back homie!");
    return 
1;

PHP Code:
forward OnAccountCheck(playerid);
public 
OnAccountCheck(playerid)
{
    new 
rowsfields;
    
cache_get_data(rowsfieldsmysql);
    if(
rows)
    {
        
cache_get_field_content(0"Password"PlayerInfo[playerid][pPassword], mysql129);
        
PlayerInfo[playerid][pID] = cache_get_field_content_int(0"ID");
        
ShowPlayerDialog(playeridLoginDialogDIALOG_STYLE_PASSWORD"Welcome Enter your password to login""Test Server""Login""Cancel");
    }
    else
    {
        
ShowPlayerDialog(playeridRegisterDialogDIALOG_STYLE_PASSWORD"Welcome Create a password to register""Test Server","Register""Cancel");
    }
    return 
1;




Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - AndySedeyn - 18.03.2016

You have to connect to your database under OnGameModeInit.

I quote the tutorial:
Quote:
Originally Posted by Overhaul
View Post
Till this point, we haven't really connected to the database yet. The connection happens in OnGameModeInit. Why? Because we would like to load all the data (not player-related) when the gamemode initializes. We use the following snippet of code to do so:
PHP Code:
public OnGameModeInit()
{
    
mysql_log(LOG_ALL);
    
mysql mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD);
    if(
mysql_errno() != 0)
    {
        
printf("[MySQL] The connection has failed.");
    }
    else
    {
        
printf("[MySQL] The connection was successful.");
    }
    return 
true;




Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - saffierr - 18.03.2016

Still nothing on connect.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - AndySedeyn - 18.03.2016

I've assisted you on Skype. The issue was that you wrapped tables and columns in single quotes (''). That doesn't work in SQL. Backticks/backquote/accent graves work (``) but are not necessarily needed. You only wrap string values in a pair of single quotes.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Konstantinos - 12.06.2016

It is the same. I'll show in detail what I mean:

Name -> '%e' -> playername
Password -> '%e' -> Player[playerid][Password]
IP -> '%e' -> playerip
Admin -> 0
VIP -> 0
Money -> 0

Until this part, everything is correct but take a closer look to the rest:

?? -> %f -> ??
?? -> %f -> ??
?? -> %f -> ??
?? -> %f -> ??

You have 4 specifiers that do not have columns nor arguments.


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - WhiteGhost - 12.06.2016

Quote:
Originally Posted by Konstantinos
View Post
It is the same. I'll show in detail what I mean:

Name -> '%e' -> playername
Password -> '%e' -> Player[playerid][Password]
IP -> '%e' -> playerip
Admin -> 0
VIP -> 0
Money -> 0

Until this part, everything is correct but take a closer look to the rest:

?? -> %f -> ??
?? -> %f -> ??
?? -> %f -> ??
?? -> %f -> ??

You have 4 specifiers that do not have columns nor arguments.
PHP Code:
  mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)"playernamePlayer[playerid][Password], playerip); 
Changed it,same problem.

Edit: shouldnt
PHP Code:
OnAccountRegister 
be
PHP Code:
OnAccountCheck 
at this line:
PHP Code:
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid); 



Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Slawiii - 13.06.2016

Nice Tuto !..


Re: [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool] - Konstantinos - 13.06.2016

Quote:
Originally Posted by WhiteGhost
View Post
PHP Code:
  mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%e', '%e', '%e', 0, 0, 0)"playernamePlayer[playerid][Password], playerip); 
Changed it,same problem.

Edit: shouldnt
PHP Code:
OnAccountRegister 
be
PHP Code:
OnAccountCheck 
at this line:
PHP Code:
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid); 
That's a valid query. Check your mysql logs and make sure the size of "query" is enough long to store the whole text.

We have already checked if an account exists and there isn't so we force the player to register. The query inserts the new row to the table and in OnAccountRegister, you get the cache_insert_id which is the value of the id (which was set with auto increment and increases itself in every new row).