MySQL Dialog Won't Open
#1

Hello, I have a register system on my website and I want it to check if that user has registered, if they haven't I want it to kick them off the server but if they have, I want it to open the login dialog box. It worked but when I removed the register part of it from my script no dialog will open:

pawn Код:
public OnPlayerConnect(playerid)
{
    MoneyGiven[playerid] = -1; // This is the MySQL login system I have
    new pname[24]; //Creates our variables.
    new string[210];
    GetPlayerName(playerid, pname, 24); //Gets the players name
    mysql_store_result(); //We store the result.
    new rows = mysql_num_rows(); //We get how many rows the query returned. // This is the MySQL login system I have
    if(!rows)
    {
        //If the rows are equal to 0. This means that the query did not find
        //anyone under the name we connected under in the database.
        //So here we send the player the register dialog.
        SendClientMessage(playerid, COLOR_LIGHTRED, "Error: Please register an account at http://127.0.0.1 before being able to play!");
        Kick(playerid);
    }
    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.
        format(string, sizeof(string), "Welcome back, %s. Please enter your password below to log in.",  GetName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Confirm", "Quit");
        IsRegistered[playerid] = 1; //Sets the registered variable to 1 (Shows that the player is registered).
    }
    return 1;
}
I have tried a registered and a non-registered name, nothing happens..
Reply
#2

You are not querying the database when the player connects, therefore any data stored there is not being found.

You need something like this:
Код:
format(query,sizeof(query),"SELECT `Username` FROM `Accounts` WHERE `Username` = '%s' LIMIT 0 , 30;",name);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
        //do something here
}
Reply
#3

Hmm nope, still no dialog, here's the dialog code:

pawn Код:
#define DIALOG_LOGIN 2
pawn Код:
case DIALOG_LOGIN: //Dialog login
        {
            if(!response) //If they click the cancel button
            {
                Kick(playerid);
            }
            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.
                    format(string, sizeof(string), "Welcome back, %s. Please enter your password below to log in.", GetName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT, "Login", string, "Confirm", "Quit");
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Error{FFFFFF}: You have entered an incorrect password."); //Sends the client a error message
                }
                mysql_free_result(); //Remember to always free a result if you stored one!
            }
            return 1;
        }
The indent at:
pawn Код:
case DIALOG_LOGIN: //Dialog login
is just the way I posted the code
Reply
#4

Can you show me what code you now have under OnPlayerConnect?
Reply
#5

Man I did it the wrong way around, your code worked for me. +rep, thanks a lot bro! You seem to know a lot about MySQL, I've learnt PHP and HTML within two weeks non stop coding all day all night to get my website set up, if I have some issues here and there could I send them in PM? I won't do this constantly
Reply
#6

Also, one question, does "mysql_store_result();" need to be used everytime something is checked in the database or everytime something is checked, deleted and inserted?
Reply
#7

I don't know PHP at the moment (i have meant to start learning but am to damn lazy.)

I suggest going to this guy http://forum.sa-mp.com/member.php?u=118954 if you need PHP help.
Reply
#8

Yeah I meant MySQL help, just stating about the PHP and HTML, looking to make a good roleplaying community like Red County RP and LS-RP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)