Mysql help
#1

Hello, i have a problem with mysql register part, seems it doesnt save the player account. If i register, then quit and i re-enter, i have to register again. This is mysql_log:

Quote:

Log("07:19:44","mysql_connect",4,"host: \"*****\", user: \"****\", database: \"****\", password: \"****\", port: 3306, autoreconnect: true",0);
Log("07:19:44","CMySQLHandle::Create",4,"creating new connection..",0);
Log("07:19:44","CMySQLHandle::CMySQLHandle",4,"con structor called",0);
Log("07:19:44","CMySQLHandle::Create",4,"connectio n created with ID = 1",0);
Log("07:19:44","CMySQLConnection::Connect",4,"conn ection was successful",0);
Log("07:19:44","CMySQLConnection::Connect",4,"auto-reconnect has been enabled",0);
Log("07:19:44","CMySQLConnection::Connect",4,"conn ection was successful",0);
Log("07:19:44","CMySQLConnection::Connect",4,"auto-reconnect has been enabled",0);
Log("07:19:44","mysql_errno",4,"connection: 1",0);
Log("07:23:34","mysql_tquery",4,"connection: 0, query: \"SELECT * FROM `Bans` WHERE (`Username` = 'TestAcc' OR `IP` = '93\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:23:34",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:23:34","cache_get_row_count",4,"connection : 1",0);
Log("07:23:34","cache_get_row_count",2,"no active cache",0);
Log("07:23:34","cache_get_row_count",4,"connection : 1",0);
Log("07:23:34","cache_get_row_count",2,"no active cache",0);
Log("07:23:34","mysql_tquery",4,"connection: 1, query: \"UPDATE ServerStats SET TotalJoins = TotalJoins + 1\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:23:34","CMySQLQuery::CMySQLQuery()",4,"con structor called",0);
Log("07:23:34","mysql_tquery",4,"scheduling query \"UPDATE ServerStats SET TotalJoins = TotalJoins + 1\"..",0);
Log("07:23:34","CMySQLQuery::Execute[()]",4,"starting query execution",1);
Log("07:23:34","CMySQLQuery::Execute[()]",4,"query was successful",1);
Log("07:23:34","CMySQLQuery::Execute[()]",4,"no callback specified, skipping result saving",1);
Log("07:23:34","CMySQLQuery::Execute[()]",4,"data being passed to ProcessCallbacks()",1);
Log("07:23:34","CMySQLQuery::~CMySQLQuery()",4,"de constructor called",0);
Log("07:23:38","mysql_escape_string",4,"source: \"123456\", connection: 1, max_len: 100",0);
Log("07:23:38","mysql_tquery",4,"connection: 0, query: \"INSERT INTO players (Username, Password, IP, RegisterDate) VALUE\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:23:38",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:23:38","mysql_tquery",4,"connection: 0, query: \"UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:23:38",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:23:38","mysql_format",4,"connection: 1, len: 500, format: \"SELECT `TotalAccounts` FROM `ServerStats`\"",0);
Log("07:24:15","mysql_tquery",4,"connection: 0, query: \"SELECT * FROM `Bans` WHERE (`Username` = 'TestAcc' OR `IP` = '93\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:24:15",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:24:15","cache_get_row_count",4,"connection : 1",0);
Log("07:24:15","cache_get_row_count",2,"no active cache",0);
Log("07:24:15","cache_get_row_count",4,"connection : 1",0);
Log("07:24:15","cache_get_row_count",2,"no active cache",0);
Log("07:24:15","mysql_tquery",4,"connection: 1, query: \"UPDATE ServerStats SET TotalJoins = TotalJoins + 1\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:24:15","CMySQLQuery::CMySQLQuery()",4,"con structor called",0);
Log("07:24:15","mysql_tquery",4,"scheduling query \"UPDATE ServerStats SET TotalJoins = TotalJoins + 1\"..",0);
Log("07:24:15","CMySQLQuery::Execute[()]",4,"starting query execution",1);
Log("07:24:15","CMySQLQuery::Execute[()]",4,"query was successful",1);
Log("07:24:15","CMySQLQuery::Execute[()]",4,"no callback specified, skipping result saving",1);
Log("07:24:15","CMySQLQuery::Execute[()]",4,"data being passed to ProcessCallbacks()",1);
Log("07:24:15","CMySQLQuery::~CMySQLQuery()",4,"de constructor called",0);
Log("07:24:17","mysql_escape_string",4,"source: \"123456\", connection: 1, max_len: 100",0);
Log("07:24:17","mysql_tquery",4,"connection: 0, query: \"INSERT INTO players (Username, Password, IP, RegisterDate) VALUE\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:24:17",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:24:17","mysql_tquery",4,"connection: 0, query: \"UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1\", callback: \"(null)\", format: \"(null)\"",0);
Log("07:24:17",""mysql_tquery"",1,"invalid connection handle (ID = 0)",0);
Log("07:24:17","mysql_format",4,"connection: 1, len: 500, format: \"SELECT `TotalAccounts` FROM `ServerStats`\"",0);

This is the server_log:

Quote:

----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[07:19:44]
[07:19:44] Server Plugins
[07:19:44] --------------
[07:19:44] Loading plugin: mysql_static.so
[07:19:44] >> plugin.mysql: R33 successfully loaded.
[07:19:44] Loaded.
[07:19:44] Loading plugin: irc.so
[07:19:44]

*** IRC Plugin v1.4.6 by Incognito loaded ***

[07:19:44] Loaded.
[07:19:44] Loading plugin: Whirlpool.so
[07:19:44]
[07:19:44] ==================
[07:19:44]
[07:19:44] Whirlpool loaded
[07:19:44]
[07:19:44] ==================
[07:19:44]
[07:19:44] Loaded.
[07:19:44] Loading plugin: crashdetect.so
[07:19:44] CrashDetect v4.15.1 is OK.
[07:19:44] Loaded.
[07:19:44] Loading plugin: streamer.so
[07:19:44]

*** Streamer Plugin v2.7.7 by Incognito loaded ***

[07:19:44] Loaded.
[07:19:44] Loading plugin: sscanf.so
[07:19:44]

[07:19:44] ===============================

[07:19:44] sscanf plugin loaded.

[07:19:44] Version: 2.8.1

[07:19:44] © 2012 Alex "******" Cole

[07:19:44] ===============================

[07:19:44] Loaded.
[07:19:44] Loaded 6 plugins.

[07:19:44]
[07:19:44] Filterscripts
[07:19:44] ---------------
[07:19:44] Loading filterscript 'sys.amx'...
[07:19:44]
[07:19:44]
[07:19:44]
[07:19:44] =======================================
[07:19:44] | |
[07:19:44] | YSI version 3.09.0684 |
[07:19:44] | By Alex "******" Cole |
[07:19:44] | |
[07:19:44] =======================================
[07:19:44]
[07:19:44] Successfully connected on DB ***
[07:19:44] -> Loaded Successfully!

[07:19:44] Date: 25/9/2015 - Time: 7:19:44
[07:19:44] __________________________________________________ _

[07:19:44] Loaded 1 filterscripts.

[07:19:44]
----------------------------------
[07:19:44] Hot Room Loaded (TDM).
[07:19:44] ----------------------------------

[07:19:44] Number of vehicle models: 0
[07:23:32] [connection] ****** requests connection cookie.
[07:23:33] [connection] incoming connection: ***** id: 0
[07:23:34] [join] TestAcc has joined the server (0:****)
[07:23:34] IsPlayerBanned called.
[07:23:50] [part] TestAcc has left the server (0:1)
[07:24:13] [connection] ******* requests connection cookie.
[07:24:14] [connection] incoming connection: **** id: 0
[07:24:15] [join] TestAcc has joined the server (0:*******)
[07:24:15] IsPlayerBanned called.
[07:24:19] [part] TestAcc has left the server (0:1)

And this is the register callback:

OnPlayerConnect:

Код:
]new rows = mysql_num_rows();
    if(!rows)
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""White"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
    }
    if(rows == 1)
    {
        new IPP[2][15];
        mysql_fetch_field_row(IPP[0],"IPP");
        GetPlayerIp(playerid, IPP[1], 15);
        if(strlen(IPP[0]) != 0 && !strcmp(IPP[0], IPP[1], true))
        {
            MySQL_Login(playerid);
        }
        else if(!strlen(IPP[0]) || strcmp(IPP[0], IPP[1], true))
        {
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""White"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
            IsRegistered[playerid] = 1;
        }
    }
    mysql_free_result();
The stock:

Код:
stock MySQL_Register(playerid, passwordstring[])
{
    new query1[570], pname[24];
    new IPP[16];
    GetPlayerIp(playerid, IPP, sizeof(IPP));
    new Bannedby[20];
    format(Bannedby, 20, "Not Banned");
    GetPlayerName(playerid, pname, 24);
    new buff[129];
	WP_Hash(buff, 129, passwordstring);
	format(query1, sizeof(query1), "INSERT INTO players (Username, Password, IP, RegisterDate) VALUES('%s', '%s', '%s', '%s')", pname, buff, IPP, InsertTimeStamp());
    mysql_function_query(mConnectionHandle, query1, false, "", "");
    Logged[playerid] = 1;
    new stats[128];
	format(stats, sizeof(stats), "UPDATE ServerStats SET TotalAccounts = TotalAccounts + 1");
	mysql_function_query(mConnectionHandle, stats, false, "", "");
    new echo[130];
    new kname[24];
    new query[500];
    mysql_format(mysql, query, sizeof(query), "SELECT `TotalAccounts` FROM `ServerStats`");
    GetPlayerName(playerid, kname, 24);
    format(echo,sizeof(echo),"0,3** System: %s (%d) (IP: %s) has registered a new account - Total Registered Players %d",pname,playerid,query);
    IRC_GroupSay(groupID, IRC_ACHANNEL, echo);
    new string[128];
    format(string, sizeof(string), "{F2C80C}* %s (%d) {FFFFFF}has registered a new account. - Total Registered Players: {F2C80C}%d", pname,playerid,query);
	SCMTA(-1, string);
	new txd[128];
	format(txd,sizeof(txd),">> You are now registered to Epic Missions - {F2C80C}Username: %s (%d)",pname,playerid);
    SCM(playerid, -1, txd);
    return 1;
}
The dialog:

Код:
if(dialogid == DIALOG_REGISTER)
    {
        if(response)
        {
            if(CheckInput(inputtext)) return SendClientMessage(playerid, 0x0000ff, "You cannot use this password.");
            if(!strlen(inputtext) || strlen(inputtext) > 100)
            {
            	SendClientMessage(playerid,COLOR_RED,"Please enter a password within the length of 1 - 100 characters.");
                ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""White"Please register",""White"Welcome to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to register!\n\n"White"Please insert a password below:", "Register", "Cancel");
            }
            else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
            {
                new escpass[100];
                mysql_real_escape_string(inputtext, escpass);
                MySQL_Register(playerid, escpass);
            }
        }
        if(!response)
        {
        SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
        KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
        }
    }
    if(dialogid == DIALOG_LOGIN)
    {
        if(!response)
        {
        SendClientMessage(playerid, COLOR_RED, "** To play you must be registered or logged in.");
        KickTimer[playerid] = SetTimerEx("KickPlayer",200,false,"d",playerid);
        }
        if(response)
        {
            new pname[24], escapepass[100];
            GetPlayerName(playerid, pname, 24);
            mysql_real_escape_string(inputtext, escapepass);
            new query[217], buff[129];
			WP_Hash(buff, 129, inputtext);
			format(query, sizeof(query), "SELECT `Username` FROM player WHERE Username = '%s' AND Password = '%s'", pname, buff);
            mysql_function_query(mConnectionHandle, query, false, "", "");
            mysql_store_result();
            new numrows = mysql_num_rows();
            if(numrows == 1) MySQL_Login(playerid);
            if(!numrows)
            {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, ""White"Please log-in", ""White"Welcome back to "Red""SERVER_NAME""White"!\n"White"In order to start playing, you have to log-in!\n\n"White"Please insert "Red"your"White" password below:", "Login", "Cancel");
                GameTextForPlayer(playerid,"~w~Wrong ~r~password.",2000,6);
            }
            mysql_free_result();
        }
    }
And i checked the db, the account doesnt get created in the "players" table.
Reply
#2

Can you show us a screen shot with your users table in mysql? The password hash might be too long for the field in MySQL.

Also, for some debugging, do this:

PHP код:
format(query1sizeof(query1), "INSERT INTO players (Username, Password, IP, RegisterDate) VALUES('%s', '%s', '%s', '%s')"pnamebuffIPPInsertTimeStamp());
mysql_function_query(mConnectionHandlequery1false"""");
print(
query1); // add this
Logged[playerid] = 1
And show us the server log afterwads.
Reply
#3

Screen:

http://s1.postimg.org/7sewr6hxb/Immagine.jpg

Log:

Код:
----------
Loaded log file: "server_log.txt".
----------

SA-MP Dedicated Server
----------------------
v0.3.7-R2, ©2005-2015 SA-MP Team

[08:11:58] 
[08:11:58] Server Plugins
[08:11:58] --------------
[08:11:58]  Loading plugin: mysql_static.so
[08:11:58]  >> plugin.mysql: R33 successfully loaded.
[08:11:58]   Loaded.
[08:11:58]  Loading plugin: irc.so
[08:11:58] 

*** IRC Plugin v1.4.6 by Incognito loaded ***

[08:11:58]   Loaded.
[08:11:58]  Loading plugin: Whirlpool.so
[08:11:58]  
[08:11:58]  ==================
[08:11:58]  
[08:11:58]   Whirlpool loaded
[08:11:58]  
[08:11:58]  ==================
[08:11:58]  
[08:11:58]   Loaded.
[08:11:58]  Loading plugin: crashdetect.so
[08:11:58]   CrashDetect v4.15.1 is OK.
[08:11:58]   Loaded.
[08:11:58]  Loading plugin: streamer.so
[08:11:58] 

*** Streamer Plugin v2.7.7 by Incognito loaded ***

[08:11:58]   Loaded.
[08:11:58]  Loading plugin: sscanf.so
[08:11:58] 

[08:11:58]  ===============================

[08:11:58]       sscanf plugin loaded.     

[08:11:58]          Version:  2.8.1        

[08:11:58]    © 2012 Alex "******" Cole  

[08:11:58]  ===============================

[08:11:58]   Loaded.
[08:11:58]  Loaded 6 plugins.

[08:11:58] 
[08:11:58] Filterscripts
[08:11:58] ---------------
[08:11:58]   Loading filterscript 'sys.amx'...
[08:11:58]  
[08:11:58]  
[08:11:58]  
[08:11:58]  ======================================= 
[08:11:58]  |                                     | 
[08:11:58]  |        YSI version 3.09.0684        | 
[08:11:58]  |        By Alex "******" Cole        | 
[08:11:58]  |                                     | 
[08:11:58]  ======================================= 
[08:11:58]  
[08:11:58] Successfully connected on DB **
[08:11:58]  -> Loaded Successfully!

[08:11:58]  Date: 25/9/2015 - Time: 8:11:58
[08:11:58]  ___________________________________________________

[08:11:58]   Loaded 1 filterscripts.

[08:11:58] 
----------------------------------
[08:11:58] Hot Room Loaded (TDM).
[08:11:58] ----------------------------------

[08:11:58] Number of vehicle models: 0
[08:13:05] [connection] ***** requests connection cookie.
[08:13:06] [connection] incoming connection: **** id: 0
[08:13:07] [join] TestAccc has joined the server (0:*****)
[08:13:07] IsPlayerBanned called.
[08:13:10] INSERT INTO players (Username, Password, IP, RegisterDate) VALUES('TestAccc', 'FD9D94340DBD72C11B37EBB0D2A19B4D05E00FD78E4E2CE8923B9EA3A54E900DF181CFB112A8A73228D1F3551680E2AD9701A4FCFB248FA7FA77B95180628BB2', '****', '25/9/2015 8:13:10')
[08:13:15] [part] TestAccc has left the server (0:1)
Reply
#4

I see the problem. Your password field is defined as varchar(45).

This password hash : FD9D94340DBD72C11B37EBB0D2A19B4D05E00FD78E4E2CE892 3B9EA3A54E900DF181CFB112A8A73228D1F3551680E2AD9701 A4FCFB248FA7FA77B95180628BB2

is longer than 45. Try increasing your password field in the table to 255. See if it works then.
Reply
#5

Same problem.

In the log i see "8:28:49] [DEBUG] mysql_tquery - connection: 0" for some queries, but in others is working good..the only problem is this..
Reply
#6

When you register, does anything get insterted into the DB?
Reply
#7

That code is really messed up. What version of MySQL plugin are you using exactly? I don't think so that mysql_function_query/mysql_tquery and functions like mysql_free_result, mysql_num_rows are part of same MySQL version. And the usage of mysql_function_query/mysql_tquery is wrong in that code. And also I don't see any code where you check if player is registered or not, nor do I see any query in mysql log which shows that you are checking if a player is registered or not. I would recommend you to read the tuts based on mysql cache functions before going on with fixing this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)