MYSQL Problem...!
#1

so following the tutorial

https://sampforum.blast.hk/showthread.php?tid=159785
about mysql system i wanted to check if it compiles well but it show errors about the mysql_query it has changed to mysql_function_query so how i must change it now? code
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;
    return 1;
}
stock MySQL_Login(playerid)
{
    new query[300], pname[24], savingstring[20];
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '%s'", pname);

    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {

        mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
        mysql_fetch_field_row(savingstring, "money"); MoneyGiven[playerid] = strval(savingstring);

    }
    mysql_free_result();
    SendClientMessage(playerid, -1, "You have been logged in!");
    Logged[playerid] = 1;
    return 1;
}

OnGameModeInit callback
    mysql_connect(mysql_host,mysq_user,mysql_database,mysql_password);
    mysql_query("CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(41), score INT(20), money INT(20), IP VARCHAR(16) )");

OnPlayerConnect callback
    MoneyGiven[playerid] = -1;
    new query[200],pname[24];
    GetPlayerName(playerid,pname,24);
    format(query,sizeof(query),"SELECT IP FROM `database` WHERE USER = `%s` LIMIT 1",pname);
    mysql_query(query);
    mysql_store_result();
    new rows = mysql_num_rows();
    if(!rows)
    {

        ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Register","Your user is {FF0000}not{FFFFFF} registered! Please {0000FF}register{FFFFFF} with a password below!","Register","Cancel");
    }
    if(rows == 1)
    {

        new IP[2][16];
        mysql_fetch_field_row(IP[0],"IP");
        GetPlayerIp(playerid, IP[1], 16);
        if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true))
        {
            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");
            IsRegistered[playerid] = 1;
        }
    }
    mysql_free_result();

    OnPlayerDisconnect

    if(Logged[playerid] == 1)
    {
        //If the player disconnects before registering,
        //we want to make sure it doesn't try update
        //so we check if the player is logged in.
        new score = GetPlayerScore(playerid); //Gets players score
        new money = GetPlayerMoney(playerid); //Gets players money
        new query[200], pname[24]; //Creates the variables
        GetPlayerName(playerid, pname, 24); //Gets the players name.
        format(query, sizeof(query), "UPDATE playerdata SET score=%d, money=%d WHERE user='%s'", score, money, pname);
        mysql_query(query);
        //No need to store a result for a update string
    }

OnDialogResponse

    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 the password is between 1 and 100 characters then we will
            //call our MySQL_register function which will register the player.
        }
        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 :).
        }
    }
    if(dialogid == 15500) //Dialog login
    {
        if(!response) //If they click the cancel button
        {
                SendClientMessage(playerid, 0xFF0000, "You must login before you spawn!"); //Sends the client a error message
                ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","Your user is {FF0000}registered{FFFFFF}! Please {0000FF}login{FFFFFF} with your password below!\n{FF0000} You must login before you spawn!","Login","Cancel"); //Shows our login dialog :).
        }
        if(response) //If the player clicked login
        {
            new query[200], pname[24], escapepass[100]; //
            GetPlayerName(playerid, pname, 24); //Gets the players name
            mysql_real_escape_string(inputtext, escapepass); //We escape the inputtext to avoid SQL injections.
            format(query, sizeof(query), "SELECT `user` FROM playerdata WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
            mysql_query(query);
            mysql_store_result();
            new numrows = mysql_num_rows();
            if(numrows == 1) MySQL_Login(playerid);
            //This means that there is a user in the database with the same
            //password that we typed, we now proceed by using the login function.
            if(!numrows)
            {
                //This means that the password that the player
                //typed was incorrect and we will resend the dialog.
                ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","Your user is {FF0000}registered{FFFFFF}! Please {0000FF}login{FFFFFF} with your password below!\n{FF0000} The password you typed was incorrect!","Login","Cancel"); //Shows our login dialog :).
                SendClientMessage(playerid, 0xFF0000, "Incorrect password!"); //Sends the client a error message
            }
            mysql_free_result(); //Remember to always free a result if you stored one!
        }
    }
errors:

pawn Код:
(74) :error 017: undefined symbol "mysql_query"
(91) : error 017: undefined symbol "mysql_query"
(114) : error 037: invalid string (possibly non-terminated string)
(114) : warning 215: expression has no effect
(114) : error 001: expected token: ";", but found "."
(114) : error 029: invalid expression, assumed zero
(114) : fatal error 107: too many error messages on one line
Reply
#2

What plugin you're using?

mysql_query was descontinued, and replaced by mysql_function_query, since r7 version.

https://sampforum.blast.hk/showthread.php?tid=337810
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)