Mysql Problem!
#1

I Haved created a UCP For Players now...
I have the ucp with XAMP(localhost)and i don't know how to connect the server to the UCP
correctly to be registered in the Tables of the UCP,when the player connect to the server in the script shouldy show a
dialog for register/login and because the Server isn't connect to the UCP the dialog isn't showing(becouse the server didn't connect to the Tables of the DATABASE)

Here are the Scripts:

When the player Connect's
pawn Код:
MoneyGiven[playerid] = -1; //Resets the variable that you will discover later in the tutorial.
    new query[200], pname[24]; //Creates our variables.
    GetPlayerName(playerid, pname, 24); //Gets the players name
    format(query, sizeof(query), "SELECT IP FROM `playerdata` WHERE user = '%s' LIMIT 1", pname); //Formats the query, view above the code for a explanation
    mysql_query(query); //This is our query function to query the string
    mysql_store_result(); //We store the result.
    new rows = mysql_num_rows(); //Here are the rows for the Tables on the UCP!
    if(rows == 0)
    {
        ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!","Register","Cancel"); //Shows our register dialog :).
    }
    if(rows == 1)
    {
        //If the rows are equal to 1, this means there is a player already registered
        //so we can initiate the login dialog to the player or check if the players
        //current IP is the same one as in the database.
        new IP[2][16]; //We create a variable with two IP strings, one for retrieving the mysql field and one for GetPlayerIP.
        mysql_fetch_field_row(IP[0],"IP");
        GetPlayerIp(playerid, IP[1], 16);
        if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true)) //Checks that the MySQL IP has a value and that they are the same.
        {
            MySQL_Login(playerid);
        }
        else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
        {
            ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","Your user is {FF0000}registered{FFFFFF}! Please {0000FF}login{FFFFFF} with your password below!","Login","Cancel"); //Shows our login dialog :).
            IsRegistered[playerid] = 1; //Sets the registered variable to 1 (Shows that the player is registered).
        }
    }
The Connection
OnGameModeInit();
pawn Код:
mysql_connect("localhost", "korisnik", "ucp", "ucp123");
        mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )");
The Defines
pawn Код:
#define mysql_host "localhost" //Has to be a string
#define mysql_user "korisnik" //Has to be a string
#define mysql_password "ucp123" //There is none for wamp unless you set one.
#define mysql_database "ucp" //Has to be a string
EDIT:Now i have changed the connections for the server
i set it like this:
pawn Код:
mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
and the dialog is showing for register when i click Register the dialog closes and don't give me the Spawn look the code
pawn Код:
if(dialogid == 15000) //If Dialog is our register dialog
    {
        if(response) //If they click the button register
        {
            if(!strlen(inputtext) || strlen(inputtext) > 100)  //Password is not 1 to 100 characters
            {
                SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-100 characters!"); //Sends the client a error message
                ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!\n {FF0000}ERROR:Please enter a password between 1-100 characters!","Register","Cancel"); //Shows our register dialog :).
            }
            else if(strlen(inputtext) > 0 && strlen(inputtext) < 100)
            {
                new escpass[100];
                mysql_real_escape_string(inputtext, escpass);
                MySQL_Register(playerid, escpass);
            }
        }
        if(!response)
        {
                SendClientMessage(playerid, 0xFF0000, "You must register before logging in!"); //Sends the client a error message
                ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!\n {FF0000}ERROR:Please enter a password !","Register","Cancel"); //Shows our register dialog :).
        }
    }
Reply


Messages In This Thread
Mysql Problem! - by 3RoR - 01.11.2012, 12:30
Re: Mysql Problem! - by InfiniTy. - 01.11.2012, 12:36
Re: Mysql Problem! - by DBan - 01.11.2012, 12:38
Re: Mysql Problem! - by 3RoR - 01.11.2012, 12:43
Re: Mysql Problem! - by InfiniTy. - 01.11.2012, 12:46
Re: Mysql Problem! - by DBan - 01.11.2012, 12:46
Re: Mysql Problem! - by 3RoR - 01.11.2012, 12:48
Re: Mysql Problem! - by InfiniTy. - 01.11.2012, 12:49
Re: Mysql Problem! - by 3RoR - 01.11.2012, 12:55
Re: Mysql Problem! - by InfiniTy. - 01.11.2012, 12:57

Forum Jump:


Users browsing this thread: 1 Guest(s)