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
#2

Well .. make create the database ucp ( if you didn't already ) and the user default for xampp is root and no password..but if you want to host it for players you should make an username and password and when you start the server it should create the tables automatically .. if not copy
PHP код:
CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16)) 
When in DB press Sql and then paste that code in.. and it should work.. if you can't do it.. send me your skype or something and i can help.
Reply
#3

This should be posted in [HiC]TheKiller's tutorial, since you copied and pasted the code, which is extremely lazy and doesn't teach you anything. No wonder why you're having trouble. Anyways, make sure that all services in XAMP are started, and ensure that all the credentials (host, user, password, and database) are correct, it's very easy to make a small mistake that messes everything up with MySQL.
Reply
#4

Here is a pictures:
http://zaslike.com/viewer.php?file=g...vnvdbipi6w.png
http://zaslike.com/viewer.php?file=l...lt8rmnwe53.png
http://zaslike.com/viewer.php?file=k...4rzm6v7kna.png
http://zaslike.com/viewer.php?file=w...7ibg627l91.png
http://zaslike.com/viewer.php?file=k...rc51pprkav.png
http://zaslike.com/viewer.php?file=m...m92rs74mk9.png

@Adytza.
-I haved created the tables and i now rename the user with root and deleted the password now looks like this:
pawn Код:
#define mysql_host "localhost" //Has to be a string
#define mysql_user "root" //Has to be a string
#define mysql_password "" //There is none for wamp unless you set one.
#define mysql_database "ucp" //Has to be a string
and it's the same, look the pictures.

@DBan
-Is the [HiC]TheKiller's is problem? or some mistake or the tutorial isn't writed good ?
The XAMP Aplications there are ON.
and look the database connect
pawn Код:
#define mysql_host "localhost" //Has to be a string
#define mysql_user "root" //Has to be a string
#define mysql_password "" //There is none for wamp unless you set one.
#define mysql_database "ucp" //Has to be a string
Reply
#5

Your server isn't connected correctly to the database..
Try this :

#define mysql_host "localhost" //Has to be a string
#define mysql_user "root" //Has to be a string
#define mysql_password "" //There is none for wamp unless you set one.
#define mysql_database "ucp" //Has to be a string
Reply
#6

Like I said above, most likely it's a MySQL connection issue, either that or you need to create the tables inside the database.

Once again, check your credentials and ensure that XAMP is running properly. (Try and go to phpmyadmin and see if you can get in properly)
Reply
#7

look the phpmyadmin
http://prntscr.com/iopem
http://prntscr.com/iopfz
i haved created the tables


EDIT:
I think the connection on the mysql is okay,i think the problem is in this stock
pawn Код:
stock MySQL_Register(playerid, passwordstring[])
{
    new query[200], pname[24], IP[16];
    GetPlayerName(playerid, pname, 24);
    GetPlayerIp(playerid, IP, 16);
    format(query, sizeof(query), "INSERT INTO playerdata (user, password, score, money, IP) VALUES('%s', SHA1('%s'), 0, 0, '%s')", pname, passwordstring, IP);
    mysql_query(query);
    SendClientMessage(playerid, -1, "You have been registered on this server!");
    Logged[playerid] = 1; //Sets the login variable
    return 1;
}
this stock is for the player when register(look up the Dialog for registration)
Reply
#8

Quote:
Originally Posted by DBan
Посмотреть сообщение
Like I said above, most likely it's a MySQL connection issue, either that or you need to create the tables inside the database.

Once again, check your credentials and ensure that XAMP is running properly. (Try and go to phpmyadmin and see if you can get in properly)
Well maybe he created the DB but not the user.. most likely like you said.. he doesn't have MySQL turned on or the db isn't created..and/or the user..

Replace what you currently have in GM with what i gave you.. try that..
Reply
#9

http://prntscr.com/iopua look the XAMP.
http://prntscr.com/iopwe look for the DATABASE.
http://prntscr.com/iopxw inside in UCP DATABASE.
Reply
#10

In gamemodeinit put
mysql_debug(1);
If you don't already have it and then post the mysql_log..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)