07.09.2013, 09:58
I'm starting to use mysql but i have this problem
Can anyone help me?
pawn Код:
error 017: undefined symbol "mysql_query"
error 017: undefined symbol "mysql_query"
public OnPlayerConnect(playerid)
{
new Query[80],string[128];
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = `%s` LIMIT 1;",GetName(playerid));
mysql_query(Query);
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!",GetName(playerid));
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Login",string,"Login","Quit");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",GetName(playerid));
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","Quit");
}
mysql_free_result();
return 1;
}
public OnPlayerConnect(playerid)
{
new Query[80],string[128];
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = `%s` LIMIT 1;",GetName(playerid));
mysql_query(Query);
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!",GetName(playerid));
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Login",string,"Login","Quit");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",GetName(playerid));
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Register",string,"Register","Quit");
}
mysql_free_result();
return 1;
}
#include <a_samp>
#include <sscanf2>
#include <a_mysql>
#undef MAX_PLAYERS
#define MAX_PLAYERS 30
#define mysql_host "localhost"
#define mysql_user "root"
#define mysql_password ""
#define mysql_database "users"
enum PlayerInfo
{
Username[23],
Password[24],
Money
}
new PInfo[MAX_PLAYERS][PlayerInfo];
main() {}
public OnGameModeInit()
{
mysql_connect(mysql_host,mysql_user,mysql_database ,mysql_password);
return 1;
}
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);
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,0,DIALOG_STYLE_INPUT,"Lo g in",string,"Login","");
}
else
{
format(string,sizeof(string),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Re gister",string,"Register","");
}
mysql_free_result();
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 1)
{
if(!response) return Kick(playerid);
if(response)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,1,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],Query[80],pName[24];
mysql_real_escape_string(inputtext, EscapedText);
GetPlayerName(playerid,pName,sizeof(pName));
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money) VALUES ('%s','%s,'0')",pName,(playerid),EscapedText);
mysql_query(Query);
SendClientMessage(playerid,-1,"You have been successfully registered!");
GivePlayerMoney(playerid,5000);
SetPlayerScore(playerid,100);
}
}
}
if(dialogid == 0)
{
if(!response) return Kick(playerid);
if(response)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,1,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;
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60],Query[80],pname[24];
mysql_real_escape_string(password, EscapedText);
GetPlayerName(playerid,pname,sizeof(pname));
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",pname,EscapedText);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() > 0)
{
SendClientMessage(playerid,-1,"You have been logged in!");
LoadStats(playerid);
}
else
{
SendClientMessage(playerid,-1,"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>", PInfo[playerid]);
mysql_free_result();
GivePlayerMoney(playerid,PInfo[playerid][Money]);
return 1;
}
#define mysql_database "users" // this is the database exported to my computer like database.sql or the one on the phpmyadmin?