MySQL Query #2
#1

Well, after sorting all of the problems in my code, I tested it and when I logged in game to see the registering / login dialog boxes and system, none of them appeared and the player can not register or login.

My code:
PHP код:
#include <a_samp>
#include <a_mysql>
#define MYSQL_HOST      "localhost"
#define MYSQL_USER      "root"
#define MYSQL_DATABASE  "playerdata"
#define MYSQL_PASSWORD  ""
enum
{
    
LoginDialog,
    
RegisterDialog
};
new
   
mysql;
native WP_Hash(buffer[], len, const str[]);
enum PlayerData
{
   
ID,
   
Name[MAX_PLAYER_NAME],
   
Password[129],
   
IP[16],
   
Admin,
   
VIP,
   
Money,
   
Deaths,
   
Kills
};
new 
Player[MAX_PLAYERS][PlayerData];
   
main()
{
    print(
"\n----------------------------------");
    print(
" Blank Gamemode by your name here");
    print(
"----------------------------------\n");
}
public 
OnGameModeInit()
{
    
mysql_log(LOG_ALL);
    
mysql mysql_connect(MYSQL_HOST,MYSQL_USERMYSQL_DATABASEMYSQL_PASSWORD);
    if(
mysql_errno() !=0)
    {
        
printf("[MySQL] The connection to the database failed.");
    }
    else
    {
        
printf("[MySQL] The connection to the database was success!");
    }
    return 
true;
}
public 
OnGameModeExit()
{
    return 
1;
}
public 
OnPlayerRequestClass(playeridclassid)
{
    
SetPlayerPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraPos(playerid1958.37831343.157215.3746);
    
SetPlayerCameraLookAt(playerid1958.37831343.157215.3746);
    return 
1;
}
forward OnAccountCheck(playerid);
public 
OnAccountCheck(playerid)
{
    new
        
rows,
        
field;
    
cache_get_data(rowsfieldmysql);
    if(
rows)
    {
        
cache_get_field_content(0"Password"Player[playerid][Password], mysql129);
        
Player[playerid][ID] = cache_get_field_content_int(0"ID");
        
ShowPlayerDialog(playeridLoginDialogDIALOG_STYLE_INPUT"Login""Welcome Player!\nYour account has been found in our database. Please fill in your password:""Login""Quit");
    }
    else
    {
        
ShowPlayerDialog(playeridRegisterDialogDIALOG_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)
{
    
TogglePlayerSpectating(playeridtrue);
    new
        
query[128],
        
playername[MAX_PLAYER_NAME];
        
    
GetPlayerName(playeridplayernamesizeof(playername));
    
mysql_format(mysqlquerysizeof(query), "SELECT `Password`, `ID` FROM `accounts` WHERE `Name` = `%e` LIMIT 1"playername);
    
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    return 
true;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    if (
strcmp("/mycommand"cmdtexttrue10) == 0)
    {
        
// Do something here
        
return 1;
    }
    return 
0;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    switch(
dialogid)
    {
        case 
LoginDialog:
        {
            if(!
response) return Kick(playerid);
            
            new
                
hashpass[129],
                
query[100],
                
playername[MAX_PLAYER_NAME];
                
            
GetPlayerName(playeridplayernamesizeof(playername));
            
WP_Hash(hashpasssizeof(hashpass), inputtext);
            if(!
strcmp(hashpassPlayer[playerid][Password]))
            {
                
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%e' LIMIT 1"playername);
                
mysql_tquery(mysqlquery"OnAccountLoad""i"playerid);
            }
            else
            {
            
SendClientMessage(playerid, -1"You have specified an incorrect password!");
            
ShowPlayerDialog(playeridLoginDialogDIALOG_STYLE_INPUT"Login""Welcome player!\nYour account has been found in our database. Please fill in your password:""Login""Quit");
            }
        }
        case 
RegisterDialog:
        {
            if(!
response) return Kick(playerid);
            if(
strlen(inputtext) < 5)
            {
                
SendClientMessage(playerid, -1"Your password must atleast contain more than 4 letters");
                return 
ShowPlayerDialog(playeridRegisterDialogDIALOG_STYLE_INPUT"Register""Welcome player!\nYour account has not been registered yet. Please fill in your desired password:""Register""Quit");
            }
            new
                
query[512],
                
playername[MAX_PLAYER_NAME],
                
playerip[16];
                
                
            
GetPlayerName(playeridplayernamesizeof(playername));
            
GetPlayerIp(playeridplayeripsizeof(playerip));
            
WP_Hash(Player[playerid][Password], 129inputtext);
            
mysql_format(mysqlquerysizeof(query), "INSERT INTO `accounts` (`Name`, `Password`, `IP`, `Admin`, `VIP`, `Money`, `Kills`, `Deaths`) VALUES ('%e', '%e', '%e', 0, 0, 0, '%d', '%d')"playernamePlayer[playerid][Password], playeripPlayer[playerid][Kills], Player[playerid][Deaths]);
            
mysql_tquery(mysqlquery"OnAccountRegister""i"playerid);
        }
    }
    return 
false;
}
forward OnAccountLoad(playerid);
public 
OnAccountLoad(playerid)
{
    
Player[playerid][Admin] = cache_get_field_content_int(0"Admin");
    
Player[playerid][VIP] = cache_get_field_content_int(0"VIP");
    
Player[playerid][Money] = cache_get_field_content_int(0"Money");
    
Player[playerid][Deaths] = cache_get_field_content_int(0"Deaths");
    
Player[playerid][Kills] = cache_get_field_content_int(0"Kills");
    
TogglePlayerSpectating(playeridfalse);
    
GivePlayerMoney(playeridPlayer[playerid][Money]);
    
SendClientMessage(playerid, -1"You have successfully logged in.");
    return 
true;
}
forward OnAccountRegister(playerid);
public 
OnAccountRegister(playerid)
{
    
Player[playerid][ID] = cache_insert_id();
    
printf("[Registeration] New account registered. Database ID: [%d]"Player[playerid][ID]);
    
TogglePlayerSpectating(playeridfalse);
    return 
true;

My database: http://imgur.com/G8NwX3C



Help with an explanation of where I went wrong will be appreciated!
Reply
#2

Anyone, please?
Reply
#3

mysql log ?
Reply
#4

The dialog boxes do not appear therefore I can't register my account nor login.
Reply
#5

Learn your quotes. Backticks (`) are not the same as quotes ('). Backticks are used to denote the enclosed value as a table or column name. Normal quotes are used to denote the enclosed value as a literal. Meaning this:
PHP код:
WHERE `Name` = `%e
is looking for rows where the column name is equal to the column whatever-%e-contains.

Only use the normal quotes for strings and just get rid of all the backticks altogether.
Reply
#6

Thanks for helping me out, sir! Really helped me and I learnt a new thing, appreciate it!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)