[Tutorial] [UPDATED 19/05/2015]MySQL Registration System [Threaded Queries + Whirlpool]
#21

Awesome work!
Reply
#22

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.
Reply
#23

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
Reply
#24

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.
Reply
#25

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

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!
Reply
#27

Awesome tutorial, thanks for the help.
Reply
#28

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

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
Reply
#30

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); 
Reply
#31

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?
Reply
#32

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?
Reply
#33

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;

Reply
#34

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;

Reply
#35

Still nothing on connect.
Reply
#36

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.
Reply
#37

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.
Reply
#38

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); 
Reply
#39

Nice Tuto !..
Reply
#40

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).
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)