mysql r7 register/login problem -
newbienoob - 18.03.2013
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.
Re: mysql r7 register/login problem -
Scenario - 18.03.2013
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.
Re: mysql r7 register/login problem -
newbienoob - 18.03.2013
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.
Re: mysql r7 register/login problem -
Scenario - 18.03.2013
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));
Re: mysql r7 register/login problem -
newbienoob - 18.03.2013
It's working D: But what did I do wrong?
Re: mysql r7 register/login problem -
Misiur - 18.03.2013
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));
Re: mysql r7 register/login problem -
Scenario - 18.03.2013
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.
Re: mysql r7 register/login problem -
Misiur - 18.03.2013
Well, tell that to people who develop BlueG mysql plugin now.
https://sampwiki.blast.hk/wiki/MySQL#mys..._escape_string - at least use this
Re: mysql r7 register/login problem -
Scenario - 18.03.2013
Well yeah, of course.
Re: mysql r7 register/login problem -
newbienoob - 18.03.2013
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","");
}
Re: mysql r7 register/login problem -
Misiur - 18.03.2013
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.
Re: mysql r7 register/login problem -
newbienoob - 19.03.2013
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!");
}
}
Re: mysql r7 register/login problem -
Vince - 19.03.2013
Where do you assign a value to pInfo[playerid][Pasword]? If either string is empty strcmp will return 0.
Re: mysql r7 register/login problem -
newbienoob - 19.03.2013
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.
Re: mysql r7 register/login problem -
newbienoob - 22.03.2013
Double post!
Re: mysql r7 register/login problem -
ReneG - 22.03.2013
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.
Re: mysql r7 register/login problem -
newbienoob - 23.03.2013
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...
Re: mysql r7 register/login problem -
ReneG - 23.03.2013
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?
Re: mysql r7 register/login problem -
newbienoob - 23.03.2013
Yea.. it's
Name | IP | Pasword | Admin | Kills