mysql r7 register/login problem
#1

I'm kinda newbie in mysql r7. So I need help in making login/register system.

pawn Код:
public OnPlayerConnect(playerid)
{
    new query[200];
    format(query,sizeof(query),"SELECT * FROM `players` WHERE `Name`=%s",name(playerid));
    mysql_function_query(connection,query,true,"CheckAccount","i",playerid);
    return 1;
}

forward CheckAccount(playerid);
public CheckAccount(playerid)
{
    new rows,fields,temp[15];
    cache_get_data(rows,fields,connection);
    if(!rows)
    {
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Register","Ok","quit");
    }
    else
    {
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Login","Ok","quit");
    }
    return 1;
}
I don't know what am I doing(lol), the dialogs don't appear.
Reply
#2

Check to see that your query is processing first of all. Use a print() function under "CheckAccount" to see if the query is returning any rows.
Reply
#3

I did this;
pawn Код:
public CheckAccount(playerid)
{
    print("checking...");
    new rows,fields,temp[15];
    cache_get_data(rows,fields,connection);
    if(!rows)
    {
        print("i dont have account :(");
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Register now","Ok","quit");
    }
    else
    {
        print("i have account :DDDDd");
        cache_get_row(0,0,temp,connection);
        pInfo[playerid][ID] = strval(temp);
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Login now","Ok","quit");
    }
    print("checked");
    return 1;
}
It didn't print anything.
Reply
#4

Which means "CheckAccount" isn't being called. Your query isn't executing...

Assuming you've set up your database properly... Try this:

pawn Код:
format(query,sizeof(query), "SELECT * FROM `players` WHERE `Name` = '%s'", name(playerid));
Reply
#5

It's working D: But what did I do wrong?
Reply
#6

Strings _have to_ be surrounded by quotes. That's why you should use mysql_format / mysql_real_escape_string.

pawn Код:
//Not like this
format(query,sizeof(query),"SELECT * FROM `players` WHERE `Name`=%s",name(playerid));
//More like this
mysql_format(connection, query, "SELECT * FROM `players` WHERE Name = '%e'", name(playerid));
Reply
#7

NO! Don't use mysql_format() it crashes the plugin when you run it on Linux.

Using the query I posted above is the proper way to do it.
Reply
#8

Well, tell that to people who develop BlueG mysql plugin now. https://sampwiki.blast.hk/wiki/MySQL#mys..._escape_string - at least use this
Reply
#9

Well yeah, of course.
Reply
#10

o.O I'm sure I have added quotes for string.. Btw, new problem ;d
I can register. Everytime I connect to server, it always shows me a register dialog.
pawn Код:
case 1: //register dialog
        {
            if(!response) return Kick(playerid);
            if(!strlen(inputtext)) return SendClientMessage(playerid,-1,"You forgot something?");
            format(query,sizeof(query),"INSERT INTO `players` (`ID`, `Name`, `IP`, `Password`, `Admin`, `Kills`) VALUES (%d, '%s', '%s', '%s', 0, 0",\
            mysql_insert_id(),name(playerid),ip,inputtext);
            mysql_function_query(connection,query,false,"testa","");
        }
Reply
#11

Oh man. Is your ID field auto_increment? mysql_insert_id doesn't go well with caching.

pawn Код:
new tmp[64];
mysql_real_escape_string(inputtext, tmp, connection);
format(query,sizeof(query),"INSERT INTO `players` VALUES (NULL, '%s', '%s', '%s', 0, 0)", name(playerid), ip, tmp);
I'll assume that you have some sort of validation for ip and nick already earlier.
Reply
#12

I've fixed it. I forgot(again) to close the bracket for VALUES ;p
But, here's another problem.. login. I can login using any password.
pawn Код:
case 2: //login dialog
        {
            if(!strlen(inputtext)) return SendClientMessage(playerid,-1,"you forgot something?");
            if(!strcmp(inputtext,pInfo[playerid][Pasword]))
            {
                format(query,sizeof(query),"SELECT * FROM `players` WHERE `Name`='%s'",name(playerid));
                mysql_function_query(connection,query,true,"OnAccountLoad","i",playerid);
            }
            else
            {
                SendClientMessage(playerid,-1,"this aint your pass!");
            }
        }
Reply
#13

Where do you assign a value to pInfo[playerid][Pasword]? If either string is empty strcmp will return 0.
Reply
#14

pawn Код:
public CheckAccount(playerid)
{
    print("checking...");
    new rows,fields;
    cache_get_data(rows,fields,connection);
    if(!rows)
    {
        print("i dont have account :(");
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register","Register now","Ok","quit");
    }
    else
    {
        print("i have account :DDDDd");
        cache_get_row(0,2,pInfo[playerid][Pasword],connection);
        ShowPlayerDialog(playerid,2,DIALOG_STYLE_INPUT,"Login","Login now","Ok","quit");
    }
    print("checked");
    return 1;
}
Just that.
Reply
#15

Double post!
Reply
#16

After the line
pawn Код:
cache_get_row(0,2,pInfo[playerid][Pasword],connection);
print pInfo[playerid][Pasword]

for future reference, enabling the debug log usually gives a good indication where your problems are.
Reply
#17

It prints nothing and here's my mysql_log
Код:
[14:05:11] Plugin succesfully loaded!
[14:05:11]  
[14:05:11]  ** MySQL Debugging enabled.
[14:05:11]  
[14:05:11] >> mysql_connect(localhost, root, server, ***) on port 3306
[14:05:11] CMySQLHandler::CMySQLHandler() - constructor called.
[14:05:11] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "server" | Username: "root"...
[14:05:11] CMySQLHandler::Connect() - Connection was successful.
[14:05:11] CMySQLHandler::Connect() - Auto-reconnect has been enabled.
[14:05:11] >> mysql_ping(Connection handle: 1)
[14:05:11] CMySQLHandler::Ping() - Connection is still alive.
[14:05:43] >> mysql_query_callback(Connection handle: 1)
[14:05:43] ProcessQueryThread(CheckAccount) - Executing query SELECT * FROM `players` WHERE `Name` = 'aaa'...
[14:05:43] ProcessQueryThread(CheckAccount) - Query was successful.
[14:05:43] ProcessQueryThread(CheckAccount) - Data caching enabled.
[14:05:43] CMySQLHandler::StoreResult() - Result was stored.
[14:05:43] CMySQLHandler::FreeResult() - Result was successfully freed.
[14:05:43] ProcessQueryThread(CheckAccount) - Data being passed to ProcessTick().
[14:05:43] CheckAccount(i) - Callback is being called...
[14:05:43] >> cache_get_data(Connection handle: 1)
[14:05:43] ProcessTick() - The cache has been cleared.
[14:06:04] >> mysql_query_callback(Connection handle: 1)
[14:06:04] ProcessQueryThread(OnAccountLoad) - Executing query SELECT * FROM `players` WHERE `Name`='aaa'...
[14:06:04] ProcessQueryThread(OnAccountLoad) - Query was successful.
[14:06:04] ProcessQueryThread(OnAccountLoad) - Data caching enabled.
[14:06:04] CMySQLHandler::StoreResult() - Result was stored.
[14:06:04] CMySQLHandler::FreeResult() - Result was successfully freed.
[14:06:04] ProcessQueryThread(OnAccountLoad) - Data being passed to ProcessTick().
[14:06:04] OnAccountLoad(i) - Callback is being called...
[14:06:04] ProcessTick() - The cache has been cleared.
[14:06:05] >> mysql_query_callback(Connection handle: 1)
[14:06:05] ProcessQueryThread(OnAccountSaved) - Executing query UPDATE `players` SET `name` = 'aaa', `IP` = '255.255.255.255', `Pasword` = '', `Admin` = 0, `Kills` = 0 WHERE `name` = ''...
[14:06:05] ProcessQueryThread(OnAccountSaved) - Query was successful.
[14:06:05] ProcessQueryThread(OnAccountSaved) - Data being passed to ProcessTick().
[14:06:05] OnAccountSaved() - Callback is being called...
Reply
#18

That's a good indication that cache_get_row isn't loading the content into that string.

Are you sure the password field is the 3rd field in your table structure?
Reply
#19

Yea.. it's
Name | IP | Pasword | Admin | Kills
Reply


Forum Jump:


Users browsing this thread: 14 Guest(s)