#1

Hello guys, i've start working on my server and i began by doing a Login and Register system, i heard that doing it by mySQL was the best way, but i have no mySQL knowledge so i decided to follow a tutorial and i did so

i followed this tutorial: https://sampforum.blast.hk/showthread.php?tid=305994

I've done everything it was said to do, and i ended up having some errors, i fixed some but now i have some errors that i can't fix

which are:
pawn Код:
C:\Users\xxx\Desktop\SAMP Server\My SAMP Server\gamemodes\Server.pwn(164) : error 017: undefined symbol "mysql_query"
C:\Users\xxx\Desktop\SAMP Server\My SAMP Server\gamemodes\Server.pwn(352) : error 017: undefined symbol "Query"
C:\Users\xxx\Desktop\SAMP Server\My SAMP Server\gamemodes\Server.pwn(352) : error 017: undefined symbol "Query"
C:\Users\xxx\Desktop\SAMP Server\My SAMP Server\gamemodes\Server.pwn(352) : error 029: invalid expression, assumed zero
C:\Users\xxx\Desktop\SAMP Server\My SAMP Server\gamemodes\Server.pwn(352) : fatal error 107: too many error messages on one line
That's why i would like to ask you for help, and help me fixing the bug!
Here is the code:

pawn Код:
#include <a_mysql>

#define mysql_host "localhost"
#define mysql_user "MyUsername"
#define mysql_password "MyPassword"
#define mysql_database "MyDatabase"

#define Regdialog 0
#define Logindialog 1
pawn Код:
enum PlayerInfo
{
    Username[23],
    Password[24],
    Money
}
new pInfo[MAX_PLAYERS][PlayerInfo];
pawn Код:
public OnGameModeInit()
{
    SetGameModeText("NFS BETA V0.1.0");
    SetTimer("SendMessages", RANDOM_MESSAGE_TIMER, true);
    mysql_connect(mysql_host,mysql_user,mysql_database ,mysql_password);
    return 1;
}
pawn Код:
public OnPlayerConnect(playerid)
{
    new Query[80],pName[24],string[164];
    GetPlayerName(playerid,pName,24);
    format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1;",pName);
    mysql_query(Query); // line 164
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
        ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login",string,"Login","");
    }
    else
    {
        format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
        ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register",string,"Register","");
    }
    mysql_free_result();
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == Regdialog)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
        }
        else
        {
            new EscapedText[60];
            mysql_real_escape_string(inputtext, EscapedText);
            format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText); // line 352
            mysql_query(Query);
            SendClientMessage(playerid,COLOR_GREEN,"You have been successfully registered!");
        }
    }
    if(dialogid == Logindialog)
    {
        if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
        }
        else
        {
            LoginPlayer(playerid,inputtext);
        }
    }
    return 1;
}
pawn Код:
stock LoginPlayer(playerid, const password[])
{
    new EscapedText[60];
    mysql_real_escape_string(password, EscapedText);
    format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",GetPName(playerid),EscapedText);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        SendClientMessage(playerid,green,"You have been logged in!");
        LoadStats(playerid);
    }
    else
    {
        SendClientMessage(playerid,red,"Wrong password!");
        Kick(playerid);
    }
    mysql_free_result();
    return 1;
}

stock LoadStats(playerid)
{
    new pName[24],Query[80];
    GetPlayerName(playerid,pName,24);
    format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `Username` = '%s' ", pName);
    mysql_query(Query);
    mysql_store_result();
    mysql_fetch_row_format(Query, "|");
    sscanf(Query, "e<p<|>s[24]s[23]i>", PlayerInfo[playerid]);
    mysql_free_result();
    GivePlayerMoney(playerid,PlayerInfo[playerid][Money]);
    return 1;
}
Hope you can help me out with this, Thank you !
Reply
#2

please add comment on line which it showing error
Reply
#3

Quote:
Originally Posted by Humza
Посмотреть сообщение
please add comment on line which it showing error
i did, but here anyways:
pawn Код:
// OnPlayerConnect
mysql_query(Query); // line 164

// OnDialogResponse
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText); // line 352
Reply
#4

Код:
format(query, sizeof(query),
Try that piece of code and replace with your current format, see if it changes anything at all.
Reply
#5

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == Regdialog)
	{
		if(strlen(inputtext) == 0)
		{
			ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
		}
		else
		{
			new Query[256], EscapedText[60];
			mysql_real_escape_string(inputtext, EscapedText);
			format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",GetPName(playerid),EscapedText); // line 352
			mysql_query(Query);
			SendClientMessage(playerid,COLOR_GREEN,"You have been successfully registered!");
		}
	}
	if(dialogid == Logindialog)
	{
		if(strlen(inputtext) == 0)
		{
			ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register - Enter your password","You are about to register a new account! \nPlease choose the password for it! \n","Register!","");
		}
		else
		{
			LoginPlayer(playerid,inputtext);
		}
	}
	return 1;
}
increase all query string min to 256
Reply
#6

What MySQL version are you using?
Reply
#7

Quote:
Originally Posted by SaintMikey
Посмотреть сообщение
Код:
format(query, sizeof(query),
Try that piece of code and replace with your current format, see if it changes anything at all.
i keep having the Errors :/

Quote:
Originally Posted by Humza
Посмотреть сообщение
increase all query string min to 256
That gives me even more errors
Reply
#8

Quote:
Originally Posted by Luis-
Посмотреть сообщение
What MySQL version are you using?
Just saw your reply now, im using the R7 one
Reply
#9

The latest MySQL version (R39-3) doesn't use mysql_query() anymore, you can either use mysql_tquery() or mysql_pquery();

https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_pquery
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)