MYSQL Not showing Login/Register Dialog
#1

As the topic name said's it...


Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case LoginDialog:
        {
            if(!response) Kick(playerid);

            new
                hashpass[129],
                query[100],
                playername[MAX_PLAYER_NAME];

            GetPlayerName(playerid, playername, sizeof(playername));
            WP_Hash(hashpass, sizeof(hashpass), inputtext);
            if(!strcmp(hashpass, PlayerInfo[playerid][Password]))
            {
                mysql_format(Database, query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1", playername);
                mysql_tquery(Database, query, "OnAccountLoad", "i", playerid);
            }
            else
            {
                SendClientMessage(playerid, -1, "You have specified an incorrect password!");
                ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
            }
        }
}
Код:
forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new rows;
    cache_get_row_count(rows);

    if(rows)
    {
        cache_get_value_name(0, "Password", PlayerInfo[playerid][Password]);
        cache_get_value_name_int(0, "ID", PlayerInfo[playerid][ID]);
        ShowPlayerDialog(playerid, LoginDialog, DIALOG_STYLE_INPUT, "Login", "Welcome player!\nYour account has been found in our database. Please fill in your password:", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, RegisterDialog, DIALOG_STYLE_INPUT, "Register", "Welcome player!\nYour account has not been registered yet. Please fill in your desired password:", "Register", "Quit");
    }
    return true;
}
Код:
public OnPlayerConnect(playerid)
{
  new pname[MAX_PLAYER_NAME], string[250 + MAX_PLAYER_NAME], query[128];

    mysql_format(Database, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1", pname);
    mysql_tquery(Database, query, "OnAccountCheck", "i", playerid);
    
}
log warning


Код:
[18:08:42] [INFO] changed log level from 'warning, error' to 'debug, info, warning, error'
[18:08:42] [DEBUG] mysql_connect("127.0.0.1", "root", "*****", "server", 0)
[18:08:42] [DEBUG] CHandleManager::Create(this=0x7e32c0, host='127.0.0.1', user='root', pass='****', db='server', options=0x7d3698)
[18:08:42] [INFO] Creating new connection handle...
[18:08:42] [WARNING] mysql_connect: no password specified
[18:08:42] [DEBUG] CConnection::CConnection(this=0x7e5ab0, host='127.0.0.1', user='root', passw='****', db='server', options=0x7d3698)
[18:08:42] [DEBUG] CConnection::CConnection - new connection = 0x7b11f0
[18:08:42] [DEBUG] CConnection::CConnection(this=0x3b30020, host='127.0.0.1', user='root', passw='****', db='server', options=0x7d3698)
[18:08:42] [DEBUG] CConnection::CConnection - new connection = 0x7f8d30
[18:08:42] [DEBUG] CThreadedConnection::WorkerFunc(this=0x3b30020, connection=0x3b30020)
[18:08:42] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x3b30020, connection=0x3b30020)
[18:08:42] [DEBUG] CConnectionPool::CConnectionPool(size=2, this=0x7e5af0)
[18:08:42] [DEBUG] CConnection::CConnection(this=0x3d04020, host='127.0.0.1', user='root', passw='****', db='server', options=0x7d3698)
[18:08:42] [DEBUG] CConnection::CConnection - new connection = 0x803218
[18:08:42] [DEBUG] CThreadedConnection::WorkerFunc(this=0x3d04020, connection=0x3d04020)
[18:08:42] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x3d04020, connection=0x3d04020)
[18:08:42] [DEBUG] CConnection::CConnection(this=0x3ed7020, host='127.0.0.1', user='root', passw='****', db='server', options=0x7d3698)
[18:08:42] [DEBUG] CConnection::CConnection - new connection = 0x80da60
[18:08:42] [DEBUG] CThreadedConnection::CThreadedConnection(this=0x3ed7020, connection=0x3ed7020)
[18:08:42] [DEBUG] CThreadedConnection::WorkerFunc(this=0x3ed7020, connection=0x3ed7020)
[18:08:42] [INFO] Connection handle with id '1' successfully created.
[18:08:42] [DEBUG] CHandleManager::Create - new handle = 0x7d7e50
[18:08:42] [DEBUG] mysql_connect: return value: '1'
[18:08:42] [DEBUG] mysql_errno(1)
[18:08:42] [DEBUG] CHandle::GetErrorId(this=0x7d7e50)
[18:08:42] [DEBUG] CConnection::GetError(this=0x7e5ab0, connection=0x7b11f0)
[18:08:42] [DEBUG] CHandle::GetErrorId - return value: true, error id: '0', error msg: ''
[18:08:42] [DEBUG] mysql_errno: return value: '0'
[18:09:04] [DEBUG] mysql_format(0, 0x039EC9C4, 128, "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = '%e' LIMIT 1")
[18:09:04] [ERROR] mysql_format: invalid connection handle '0'
[18:09:04] [DEBUG] mysql_tquery(0, "", "OnAccountCheck", "i")
[18:09:04] [ERROR] mysql_tquery: invalid connection handle '0'
[18:09:04] [DEBUG] mysql_tquery: return value: '0'
Reply
#2

The pname string into OnPlayerConnect is not setted, use GetPlayerName(playerid,pname,sizeof(pname)); once format the query
Reply
#3

Quote:
Originally Posted by Criniti
Посмотреть сообщение
The pname string into OnPlayerConnect is not setted, use GetPlayerName(playerid,pname,sizeof(pname)); once format the query
Didn't notice i had it at the bottom code...
thanks


the errors are now

Код:
[22:39:21] [DEBUG] mysql_format(0, 0x03A089D4, 128, "SELECT `Password`, `ID` FROM `accounts` WHERE `Username` = '%e' LIMIT 1")
[22:39:21] [ERROR] mysql_format: invalid connection handle '0'
[22:39:21] [DEBUG] mysql_tquery(0, "", "OnAccountCheck", "i")
[22:39:21] [ERROR] mysql_tquery: invalid connection handle '0'
[22:39:21] [DEBUG] mysql_tquery: return value: '0'
Код:
    mysql_format(Database, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Username` = '%e' LIMIT 1", pname);
    mysql_tquery(Database, query, "OnAccountCheck", "i", playerid);
Reply
#4

Invalid Connection Handle means MySQL was not able to connect to database.

Quote:

[22:39:21] [ERROR] mysql_format: invalid connection handle '0'

Reply
#5

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Invalid Connection Handle means MySQL was not able to connect to database.
My server saids it's connected

Код:
[22:38:02] [MySQL] The connection was successful.
Reply
#6

Show me where you have Connected to Database under OnGameModeInit. and which version of MySQL you're using.
Reply
#7

Quote:
Originally Posted by GTLS
Посмотреть сообщение
Show me where you have Connected to Database under OnGameModeInit. and which version of MySQL you're using.
I'm using r41

Код:
  mysql_connect("127.0.0.1", "root", "", "server");
    if(mysql_errno(Database) == 0)
    {
        printf("[MySQL] The connection has failed.");
    }
    else
    {
        printf("[MySQL] The connection was successful.");
    }
I'm thinking it's related to this?

Код:
    mysql_format(Database, query, sizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Username` = '%e' LIMIT 1", pname);
    mysql_tquery(Database, query, "OnAccountCheck", "i", playerid);
Reply
#8

You should have a MySQL: Connection handle, which is "Database" in your case, catching the value from mysql_connect.

PHP код:
 Database mysql_connect(...); 
Also, mysql_errno() returns 0 if connection was successful. So you've got that wrong. So basically, the problem is that mysql is not able to connect as I said above.
https://sampwiki.blast.hk/wiki/MySQL/R40#mysql_errno - Here, look at this.
Reply
#9

I don't get it
but when i shut off xampp and still gonna said its on but i see
but i don't get it
Reply
#10

This:
PHP код:
mysql_connect("127.0.0.1""root""""server");
    if(
mysql_errno(Database) == 0)
    {
        
printf("[MySQL] The connection has failed.");
    }
    else
    {
        
printf("[MySQL] The connection was successful.");
    } 
Should be,

PHP код:
new MySQL:Database//On the Top

Database mysql_connect("127.0.0.1""root""""server");
    if(
mysql_errno() == 0)
    {
         
printf("[MySQL] The connection was successful.");
    }
    else
    {
           
printf("[MySQL] The connection has failed."); 
    } 
mysql_errnno() will return -1 if there was any error. And 0 if there were no error. I sent you the link of wiki above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)