MySQL Register/Login system problems
#1

Well, I just learned how to use MySQL for the first time today and this is the first system I'm trying to do with it.
So while trying to make a register/login system I encountered a few issues.

1. Account doesn't really get registered, every time I log into the server with the same name, it always asks me to register, even though I have already registered several times before using this name.

2. When I'm trying to log in, it /ALWAYS/ says the password is wrong, even though the password is actually the same one I used to register with.

OnPlayerConnect:
PHP код:
public OnPlayerConnect(playerid)
{
    
SetPlayerColor(playeridCOLOR_WHITE);
    new 
name[MAX_PLAYER_NAME+1],
        
string[128];
    
GetPlayerName(playeridnamesizeof(name));
    
format(stringsizeof(string), "SELECT * FROM 'users' WHERE 'username' = '%s'"name);
    
mysql_query(string);
    
mysql_store_result();
    if(
mysql_num_rows() <= 0RegisterPlayer(playerid);
    else if(
mysql_num_rows() >= 1LoginPlayer(playerid);
    
mysql_free_result();
    return 
1;

RegisterPlayer:
PHP код:
RegisterPlayer(playerid)
{
    
ShowPlayerDialog(playerid1DIALOG_STYLE_INPUT"Register""Please enter the password for your new account.""Submit""Cancel");
    return 
1;

LoginPlayer:
PHP код:
LoginPlayer(playerid)
{
    
ShowPlayerDialog(playerid2DIALOG_STYLE_INPUT"Login""This account is registered, please enter the password.""Submit""Cancel");
    return 
1;

OnDialogResponse:
PHP код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
if(
response)
{
    switch(
dialogid)
    {
        case 
1:
        {
            if(
strlen(inputtext) < || strlen(inputtext) > 30)
            {
                
SendClientMessage(playeridCOLOR_RED"[Error] The password's length must be between 3~30");
                
ShowPlayerDialog(playerid1DIALOG_STYLE_INPUT"Register""Password too short/long, enter a new one!""Submit""Cancel");
                return 
1;
            }
            new 
string[128],
                
name[MAX_PLAYER_NAME+1];
            
GetPlayerName(playeridnamesizeof(name));
            
format(stringsizeof(string), "INSERT INTO 'users' ('username', 'password') VALUES ('%s', '%s')"nameinputtext);
            
mysql_query(string);
            
SendClientMessage(playeridCOLOR_LIGHTBLUE"[SUCCESS] Your account has been created, please log in now.");
            
LoginPlayer(playerid);
        }
        case 
2:
        {
            new 
string[128],
                
name[MAX_PLAYER_NAME+1];
            
GetPlayerName(playeridnamesizeof(name));
            
format(stringsizeof(string), "SELECT * FROM 'users' WHERE 'username' = '%s' AND 'password' = '%s'"nameinputtext);
               
mysql_query(string);
               
mysql_store_result();
               if(
mysql_num_rows() <= 0)
            {
                
SendClientMessage(playeridCOLOR_RED"[Error] Wrong password!");
                
ShowPlayerDialog(playerid2DIALOG_STYLE_INPUT"Login""Wrong password, enter the correct one!""Submit""Cancel");
                return 
1;
            }
            else 
SendClientMessage(playeridCOLOR_WHITE"[SUCCESS] You have successfully logged in!");
        }
    }
}
return 
1;

Reply


Messages In This Thread
MySQL Register/Login system problems - by Tomer!.$ - 04.09.2013, 10:07
Re: MySQL Register/Login system problems - by Army - 04.09.2013, 10:30
Re: MySQL Register/Login system problems - by Tomer!.$ - 04.09.2013, 10:37
Re: MySQL Register/Login system problems - by Vince - 04.09.2013, 10:43
Re: MySQL Register/Login system problems - by Army - 04.09.2013, 10:46
Re: MySQL Register/Login system problems - by Tomer!.$ - 04.09.2013, 10:49
Re: MySQL Register/Login system problems - by Dragonsaurus - 04.09.2013, 10:50

Forum Jump:


Users browsing this thread: 2 Guest(s)