SA-MP Forums Archive
MYSQL help please. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MYSQL help please. (/showthread.php?tid=538472)



MYSQL help please. - TonyII - 21.09.2014

Hey, so I started messing around with MYSQL hoping that I could learn more about it. I went through a few tutorials but I end up with one problem.
pawn Код:
//So the problem is everytime I try to log in, I enter the correct password the player won't log.
//When I enter my password the dialog dissappears and nothing happens, after a while I crash.
//Registering and all other stuff are working great but I just end up with this, any help is appreciated

    if(dialogid == DIALOG_LOGIN)
    {
    if(!response) return Kick (playerid);
    if(response)
    {
        new query[256], EncryptedPass[130];
        WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
        format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GPN(playerid), EncryptedPass);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows() != 0)
        {
            LoadPlayer(playerid);
        }
        else
        {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{FF8000}Login","{FFFFFF}Wrong password.\nLogin below with the password you registered with.","Login","Quit");
        }
    }
    }

//LoadPlayer
stock LoadPlayer(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", GPN(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(query, "ID"); PlayerInfo[playerid][pID] = strval(query);
        mysql_fetch_field_row(PlayerInfo[playerid][pName], "Name");
        mysql_fetch_field_row(PlayerInfo[playerid][pPass], "Password");
    }
    SendClientMessage(playerid,COLOR_WHITE,"WB");
    SetSpawnInfo(playerid,0,0,0,0,0,0,0,0,0,0,0,0);
    SpawnPlayer(playerid);
    TogglePlayerSpectating(playerid, 0);
    SetCameraBehindPlayer(playerid);
    //SetPlayerPos(playerid,PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]);
    if(PlayerInfo[playerid][pVModel] > 0)
    {
    PlayerInfo[playerid][pVehicle] = CreateVehicle(PlayerInfo[playerid][pVModel],PlayerInfo[playerid][pVX],PlayerInfo[playerid][pVY],PlayerInfo[playerid][pVZ],PlayerInfo[playerid][pVA],PlayerInfo[playerid][pVColor1],PlayerInfo[playerid][pVColor2],-1);
    Fuel[PlayerInfo[playerid][pVehicle]] = PlayerInfo[playerid][pVFuel];
    for(new i = 0; i < MAX_MODS; i++)
    {
    AddVehicleComponent(PlayerInfo[playerid][pVehicle], PlayerInfo[playerid][pVMods][i]);
    }
    }
    return 1;
}



Re: MYSQL help please. - MrCallum - 21.09.2014

You need to make a valid database or a storage for the users!


Re: MYSQL help please. - iSkate - 21.09.2014

I'm not good in MySQL, in fact I don't know shit about it but you should post your server log so other people can easily help you.


Re: MYSQL help please. - Vince - 21.09.2014

Quote:
Originally Posted by TonyII
Посмотреть сообщение
so I started messing around with MYSQL
And yet you start with obsolete methods? If you're a starter it's easier to learn the newer methods now, rather than to have to upgrade later, with all foreseeable problems at that.


Re: MYSQL help please. - TonyII - 21.09.2014

Quote:
Originally Posted by MrCallum
Посмотреть сообщение
You need to make a valid database or a storage for the users!
There is a valid database, wich I haven't provided here on the post.

Quote:
Originally Posted by inshal
Посмотреть сообщение
I'm not good in MySQL, in fact I don't know shit about it but you should post your server log so other people can easily help you.
I think that people who are familier with mysql would recognize such problems without the help of logs, also the logs don't provide anything except for me connecting and leaving.

Quote:
Originally Posted by Vince
Посмотреть сообщение
And yet you start with obsolete methods? If you're a starter it's easier to learn the newer methods now, rather than to have to upgrade later, with all foreseeable problems at that.
This was recommended to me, I would appreciate it if you could link me some of the methods you're talking about.


Re: MYSQL help please. - TonyII - 22.09.2014

Dump


Re: MYSQL help please. - Eth - 22.09.2014

change this :
pawn Код:
format(query, sizeof(query), "SELECT * FROM accounts WHERE name = '%s' AND password = '%s'", GPN(playerid), EncryptedPass);
        mysql_query(query);
to this:
pawn Код:
format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `name` = '%s' AND `password` = '%s'", GPN(playerid), EncryptedPass);
        mysql_query(query);



Re: MYSQL help please. - TonyII - 22.09.2014

Thanks for the help but I get the same result, I now start to have my doubts that the problem is in MySQL.
So this happens

I enter wrong password.

Correct password


All of the necessary codes.
pawn Код:
if(dialogid == DIALOG_LOGIN)
    {
    if(!response) return Kick (playerid);
    if(response)
    {
        new query[256], EncryptedPass[130];
        WP_Hash(EncryptedPass, sizeof(EncryptedPass), inputtext);
        format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `name` = '%s' AND `password` = '%s'", GPN(playerid), EncryptedPass);
        mysql_query(query);
        mysql_store_result();
        if(mysql_num_rows() != 0)
        {
            LoadPlayer(playerid);
        }
        else
        {
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"{FF8000}Login","{FFFFFF}Wrong password.\nLogin below with the password you registered with.","Login","Quit");
        }
    }
    }
    if(dialogid == DIALOG_REGISTER) // This  works perfectly fine, no trouble with this
    {
    if(!response) return Kick(playerid);
    if(response)
    {
        if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "{FF8000}Register","Incorrect password.\nInsert a valid password below.","Register","Quit");
        RegisterPlayer(playerid, inputtext);

    }
    }

stock LoadPlayer(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT * FROM accounts WHERE Name = '%s'", GPN(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(query, "ID"); PlayerInfo[playerid][pID] = strval(query);
        mysql_fetch_field_row(PlayerInfo[playerid][pName], "Name");
        mysql_fetch_field_row(PlayerInfo[playerid][pPass], "Password");
    }
    SendClientMessage(playerid,COLOR_WHITE,"WB");
    SetSpawnInfo(playerid,0,0,0,0,0,0,0,0,0,0,0,0);
    SpawnPlayer(playerid);
    TogglePlayerSpectating(playerid, 0);
    SetCameraBehindPlayer(playerid);
    //SetPlayerPos(playerid,PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]);
    if(PlayerInfo[playerid][pVModel] > 0)
    {
    PlayerInfo[playerid][pVehicle] = CreateVehicle(PlayerInfo[playerid][pVModel],PlayerInfo[playerid][pVX],PlayerInfo[playerid][pVY],PlayerInfo[playerid][pVZ],PlayerInfo[playerid][pVA],PlayerInfo[playerid][pVColor1],PlayerInfo[playerid][pVColor2],-1);
    Fuel[PlayerInfo[playerid][pVehicle]] = PlayerInfo[playerid][pVFuel];
    for(new i = 0; i < MAX_MODS; i++)
    {
    AddVehicleComponent(PlayerInfo[playerid][pVehicle], PlayerInfo[playerid][pVMods][i]);
    }
    }
    return 1;
}

stock RegisterPlayer(playerid, regpass[])
{
    new query[256], EncryptedPass[130];
    WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
    format(query, sizeof(query), "INSERT INTO accounts (Name, Password) VALUES ('%s', '%s')", GPN(playerid), EncryptedPass);
    mysql_query(query);
    PlayerInfo[playerid][pLevel] = 1;
    SetPlayerScore(playerid, 1);
    Registration[playerid] = 1;
    PlayerInfo[playerid][pHealth] = 100;
    if(Registration[playerid] == 1)
    {
    ShowPlayerDialog(playerid,DIALOG_GENDER,DIALOG_STYLE_MSGBOX,"{FF8000}Gender","{FFFFFF}What is your characters gender?","Male","Female");
    return 1;
    }
    return 1;
}



Re: MYSQL help please. - Eth - 22.09.2014

pawn Код:
stock RegisterPlayer(playerid, regpass[])
{
    new query[256], EncryptedPass[130];
    WP_Hash(EncryptedPass, sizeof(EncryptedPass), regpass);
    format(query, sizeof(query), "INSERT INTO `accounts` (`Name`, `Password`) VALUES ('%s', '%s')", GPN(playerid), EncryptedPass);
    mysql_query(query);
    PlayerInfo[playerid][pLevel] = 1;
    SetPlayerScore(playerid, 1);
    Registration[playerid] = 1;
    PlayerInfo[playerid][pHealth] = 100;
    if(Registration[playerid] == 1)
    {
    ShowPlayerDialog(playerid,DIALOG_GENDER,DIALOG_STYLE_MSGBOX,"{FF8000}Gender","{FFFFFF}What is your characters gender?","Male","Female");
    return 1;
    }
    return 1;
}
pawn Код:
stock LoadPlayer(playerid)
{
    new query[128];
    format(query, sizeof(query), "SELECT * FROM `accounts` WHERE `Name` = '%s'", GPN(playerid));
    mysql_query(query);
    mysql_store_result();
    while(mysql_fetch_row_format(query,"|"))
    {
        mysql_fetch_field_row(query, "ID"); PlayerInfo[playerid][pID] = strval(query);
        mysql_fetch_field_row(PlayerInfo[playerid][pName], "Name");
        mysql_fetch_field_row(PlayerInfo[playerid][pPass], "Password");
    }
    SendClientMessage(playerid,COLOR_WHITE,"WB");
    SetSpawnInfo(playerid,0,0,0,0,0,0,0,0,0,0,0,0);
    SpawnPlayer(playerid);
    TogglePlayerSpectating(playerid, 0);
    SetCameraBehindPlayer(playerid);
    //SetPlayerPos(playerid,PlayerInfo[playerid][pPosX],PlayerInfo[playerid][pPosY],PlayerInfo[playerid][pPosZ]);
    if(PlayerInfo[playerid][pVModel] > 0)
    {
    PlayerInfo[playerid][pVehicle] = CreateVehicle(PlayerInfo[playerid][pVModel],PlayerInfo[playerid][pVX],PlayerInfo[playerid][pVY],PlayerInfo[playerid][pVZ],PlayerInfo[playerid][pVA],PlayerInfo[playerid][pVColor1],PlayerInfo[playerid][pVColor2],-1);
    Fuel[PlayerInfo[playerid][pVehicle]] = PlayerInfo[playerid][pVFuel];
    for(new i = 0; i < MAX_MODS; i++)
    {
    AddVehicleComponent(PlayerInfo[playerid][pVehicle], PlayerInfo[playerid][pVMods][i]);
    }
    }
    return 1;
}



Re: MYSQL help please. - TonyII - 22.09.2014

I really appreciate the help but I still got the same result