Mysql problem
#7

This don't work to. When i registered and type command /q to quit going again in my server it show me the dialog register again don't show the dialog login

here's the full code

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <a_mysql>

#undef MAX_PLAYERS
#define MAX_PLAYERS 30

#define mysql_host "localhost"
#define mysql_user "root"
#define mysql_password ""
#define mysql_database "users"

enum PlayerInfo
{
    Username[23],
    Password[24],
    Money
}
new PInfo[MAX_PLAYERS][PlayerInfo];

main() {}

public OnGameModeInit()
{
    mysql_connect(mysql_host,mysql_user,mysql_database ,mysql_password);
    return 1;
}

public OnPlayerConnect(playerid)
{
    new Query[80],pName[24],string[164];
    GetPlayerName(playerid,pName,24);
    format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
        ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Lo g in",string,"Login","");
    }
    else
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Re gister",string,"Register","");
    }
    mysql_free_result();
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 1)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(strlen(inputtext) == 0)
            {
            ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
            }
            else
            {
                new EscapedText[60],Query[80],pName[24];
                mysql_real_escape_string(inputtext, EscapedText);
                GetPlayerName(playerid,pName,sizeof(pName));
                format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",pName,(playerid),EscapedText);
                mysql_query(Query);
                SendClientMessage(playerid,-1,"You have been successfully registered!");
                GivePlayerMoney(playerid,5000);
                SetPlayerScore(playerid,100);
            }
        }
    }
    if(dialogid == 0)
    {
        if(!response) return Kick(playerid);
        if(response)
        {
            if(strlen(inputtext) == 0)
            {
            ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
            }
            else
            {
                LoginPlayer(playerid,inputtext);
            }
        }
    }
    return 1;
}

stock LoginPlayer(playerid,const password[])
{
    new EscapedText[60],Query[80],pname[24];
    mysql_real_escape_string(password, EscapedText);
    GetPlayerName(playerid,pname,sizeof(pname));
    format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",pname,EscapedText);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() > 0)
    {
        SendClientMessage(playerid,-1,"You have been logged in!");
        LoadStats(playerid);
    }
    else
    {
        SendClientMessage(playerid,-1,"Wrong password!");
        Kick(playerid);
    }
    mysql_free_result();
    return 1;
}

stock LoadStats(playerid)
{
    new pName[24],Query[80];
    GetPlayerName(playerid,pName,24);
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `Username` = '%s' ", pName);
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_row_format(Query, "|");
    sscanf(Query, "e<p<|>s[24]s[23]i>", PInfo[playerid]);
    mysql_free_result();
    GivePlayerMoney(playerid,PInfo[playerid][Money]);
    return 1;
}
and 1 more question
pawn Код:
#define mysql_database "users" // this is the database exported to my computer like database.sql or the one on the phpmyadmin?
Reply


Messages In This Thread
Mysql problem - by xganyx - 07.09.2013, 09:58
Re: Mysql problem - by Konstantinos - 07.09.2013, 10:00
Re: Mysql problem - by Patrick - 07.09.2013, 10:07
Re: Mysql problem - by xganyx - 07.09.2013, 10:28
Re: Mysql problem - by jasonsmith - 07.09.2013, 10:42
Re: Mysql problem - by Tomer!.$ - 07.09.2013, 10:45
Re: Mysql problem - by xganyx - 07.09.2013, 10:58
Re: Mysql problem - by Konstantinos - 07.09.2013, 10:59
Re: Mysql problem - by xganyx - 07.09.2013, 11:02

Forum Jump:


Users browsing this thread: 1 Guest(s)