switch(dialogid) { case dlogin: //login dialog { if(!response) Kick(playerid); //if they clicked Quit, we will kick them new hpass[129]; //for password hashing new query[100]; // for formatting our query. WP_Hash(hpass, 129, inputtext); //hashing inputtext if(!strcmp(hpass, PlayerInfo[playerid][Password])) //remember we have loaded player's password into this variable, pInfo[playerid][Password] earlier. Now let's use it to compare the hashed password with password that we load { //if the hashed password matches with the loaded password from database mysql_format(mysql, query, sizeof(query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]); //let's format our query //We select all rows in the table that has your name and limit the result to 1 mysql_tquery(mysql, query, "OnAccountLoad", "i", playerid); //lets execute the formatted query and when the execution is done, a callback OnAccountLoad will be called //You can name the callback however you like } else //if the hashed password didn't match with the loaded password(pInfo[playerid][Password]) { //we tell them that they have inserted a wrong password ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login\nWrong password!", "Login", "Quit"); } } case dregister: //register dialog { if(!response) return Kick(playerid); //if they clicked Quit, we will kick them if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Test - Login", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit"); //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long! new query[300]; WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); //hashing inputtext mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`) VALUES ('%e', '%s', '%s', 0, 0, 0, 0.0, 0.0, 0.0)", Name[playerid], PlayerInfo[playerid][Password], IP[playerid]); //Now let's create a new row and insert player's information in it mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid); //let's execute the query } }
forward OnAccountRegister(playerid); public OnAccountRegister(playerid) { PlayerInfo[playerid][ID] = cache_insert_id(); //loads the ID of the player in the variable once they registered. printf("New account registered. ID: %d", PlayerInfo[playerid][ID]); //just for debugging. return 1; }
[08:11:13] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1" [08:11:13] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'Test'", callback: "OnAccountCheck", format: "i" [08:11:13] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution [08:11:13] [DEBUG] cache_get_data - connection: 1 [08:11:13] [WARNING] cache_get_data - no active cache [08:11:13] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - query was successfully executed within 68.744 milliseconds [08:11:13] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [08:11:13] [DEBUG] Calling callback "OnAccountCheck".. [08:11:13] [DEBUG] cache_get_data - connection: 1 [08:11:13] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called [08:11:18] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `PosX` ,`PosY`, `PosZ`) VALUES ('%e', '%s', '%s', ..." [08:11:18] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `players` (`Username`, `Password`, `IP`, `Admin`, `V", callback: "OnAccountRegister", format: "i" [08:11:18] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution [08:11:18] [ERROR] CMySQLQuery::Execute[OnAccountRegister] - (error #1054) Unknown column 'PosX' in 'field list' [08:11:18] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - error will be triggered in OnQueryError
The error is pretty self explanatory.
CMySQLQuery::Execute[OnAccountRegister] - (error #1054) Unknown column 'PosX' in 'field list' You don't have PosX, PosY, PosZ columns in your table. Don't just copy and paste the code. Write it line by line, understand it, modify it. That is the only way to learn. |
[10:04:13] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'Test.", callback: "OnAccountCheck", format: "i" [10:04:13] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution
[10:04:13] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called [10:04:15] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)" [10:04:15] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `V", callback: "OnAccountRegister", format: "i" [10:04:15] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution [10:04:15] [ERROR] CMySQLQuery::Execute[OnAccountRegister] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 [10:04:15] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - error will be triggered in OnQueryError
mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]); mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
[11:15:34] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "sampserver", password: "****", port: 3306, autoreconnect: true, pool_size: 2 [11:15:34] [DEBUG] CMySQLHandle::Create - creating new connection.. [11:15:34] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called [11:15:34] [DEBUG] CMySQLHandle::Create - connection created (id: 1) [11:15:34] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [11:15:34] [DEBUG] CMySQLConnection::Connect - connection was successful [11:15:34] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [11:15:34] [DEBUG] mysql_errno - connection: 1 [11:15:34] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [11:15:34] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [11:15:34] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [11:15:34] [DEBUG] CMySQLConnection::Connect - connection was successful [11:15:34] [DEBUG] CMySQLConnection::Connect - connection was successful [11:15:34] [DEBUG] CMySQLConnection::Connect - connection was successful [11:15:34] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [11:15:52] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1" [11:15:52] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'Test", callback: "OnAccountCheck", format: "i" [11:15:52] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution [11:15:52] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - query was successfully executed within 56.780 milliseconds [11:15:52] [DEBUG] cache_get_data - connection: 1 [11:15:52] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [11:15:52] [WARNING] cache_get_data - no active cache [11:15:52] [DEBUG] Calling callback "OnAccountCheck".. [11:15:52] [DEBUG] cache_get_data - connection: 1 [11:15:52] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called [11:15:54] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)" [11:15:54] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `V", callback: "OnAccountRegister", format: "i" [11:15:55] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution [11:15:55] [ERROR] CMySQLQuery::Execute[OnAccountRegister] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1 [11:15:55] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - error will be triggered in OnQueryError
case dregister: //register dialog { if(!response) return Kick(playerid); //if they clicked Quit, we will kick them if(strlen(inputtext) < 6) return ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Test - Login", "In order to play, you need to register.\nYour password must be at least 6 characters long!", "Register", "Quit"); //strlen checks a lenght of a string. so if player types their password that is lower than 6, we tell them; Your password must be at least 6 characters long! new query[300]; WP_Hash(PlayerInfo[playerid][Password], 129, inputtext); //hashing inputtext mysql_format(mysql, query, sizeof(query), "INSERT INTO `Players` (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`)", Name[playerid], PlayerInfo[playerid][Password], IP[playerid]); //Now let's create a new row and insert player's information in it mysql_tquery(mysql, query, "OnAccountRegister", "i", playerid); //let's execute the query }
new query[128]; GetPlayerName(playerid, Name[playerid], 24); GetPlayerIp(playerid, IP[playerid], 16); mysql_format(mysql, query, sizeof(query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", Name[playerid]); mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid); SetTimerEx("OnAccountCheck", 100, false, "i", playerid);
mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
forward OnAccountCheck(playerid); //Now once the query has been processed; public OnAccountCheck(playerid) { new rows, fields; //a variable that will be used to retrieve rows and fields in the database. cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database. if(rows) //if there is row {//then cache_get_field_content(0, "Password", PlayerInfo[playerid][Password], mysql, 129); //we will load player's password into pInfo[playerid][Password] to be used in logging in PlayerInfo[playerid][ID] = cache_get_field_content_int(0, "ID"); //now let's load player's ID into pInfo[playerid][ID] so we can use it later printf("%s", PlayerInfo[playerid][Password]); //OPTIONAL: Just for debugging. If it didn't show your password, then there must be something wrong while getting player's password ShowPlayerDialog(playerid, dlogin, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit"); //And since we found a result from the database, which means, there is an account; we will show a login dialog } else //if we didn't find any rows from the database, that means, no accounts were found { ShowPlayerDialog(playerid, dregister, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit"); //So we show them a dialog register } return 1; }
[09:57:28] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "Test", password: "****", port: 3306, autoreconnect: true, pool_size: 2 [09:57:28] [DEBUG] CMySQLHandle::Create - creating new connection.. [09:57:28] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called [09:57:28] [DEBUG] CMySQLHandle::Create - connection created (id: 1) [09:57:28] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [09:57:28] [DEBUG] CMySQLConnection::Connect - connection was successful [09:57:28] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [09:57:28] [DEBUG] mysql_errno - connection: 1 [09:57:28] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [09:57:28] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [09:57:28] [DEBUG] CMySQLConnection::Connect - establishing connection to database... [09:57:28] [DEBUG] CMySQLConnection::Connect - connection was successful [09:57:28] [DEBUG] CMySQLConnection::Connect - connection was successful [09:57:28] [DEBUG] CMySQLConnection::Connect - connection was successful [09:57:28] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [09:57:28] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled [09:58:06] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1" [09:58:06] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'Deric", callback: "OnAccountCheck", format: "i" [09:58:06] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution [09:58:06] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - query was successfully executed within 5.367 milliseconds [09:58:06] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [09:58:06] [DEBUG] cache_get_data - connection: 1 [09:58:06] [WARNING] cache_get_data - no active cache [09:58:06] [DEBUG] Calling callback "OnAccountCheck".. [09:58:06] [DEBUG] cache_get_data - connection: 1 [09:58:06] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called [09:58:08] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO Players (`Username`, `Password`, `IP`, `Admin`, `VIP`, `Money`) VALUES ('%s', '%s', '%s', '0', '0', '0');" [09:58:08] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO Players (`Username`, `Password`, `IP`, `Admin`, `VIP", callback: "OnAccountRegister", format: "i" [09:58:08] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - starting query execution [09:58:08] [DEBUG] CMySQLQuery::Execute[OnAccountRegister] - query was successfully executed within 129.564 milliseconds [09:58:08] [DEBUG] CMySQLResult::CMySQLResult() - constructor called [09:58:08] [DEBUG] Calling callback "OnAccountRegister".. [09:58:08] [DEBUG] cache_insert_id - connection: 1 [09:58:08] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called