12.11.2013, 23:51
Hey folks!
Today, I tried to convert my script into MySQL but it didn't work correctly, Whenever I try to create a new account it doesn't get saved. So I tried inserting the data through PhpMyAdmin and I could login, it reads the data correctly from the Database, the problem is it's not saving the account into the table. (It just worked through PhpMyAdmin)
OnGameModeInit
OnPlayerConnect
OnDialogResponse
Stocks
Thanks in advance
Today, I tried to convert my script into MySQL but it didn't work correctly, Whenever I try to create a new account it doesn't get saved. So I tried inserting the data through PhpMyAdmin and I could login, it reads the data correctly from the Database, the problem is it's not saving the account into the table. (It just worked through PhpMyAdmin)
OnGameModeInit
pawn Код:
#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password ""
#define mysql_database "samp server"
mysql_connect(mysql_host,mysql_user,mysql_database ,mysql_password);
mysql_debug(1);
OnPlayerConnect
pawn Код:
new Query[80],pName[24],tstring[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(tstring,sizeof(tstring),"Hey, %s! \nYour account is not registered. \nPlease register to continue!",pName);
ShowPlayerDialog(playerid,Regdialog,DIALOG_STYLE_INPUT,"Re gister",tstring,"Register","");
}
else
{
format(tstring,sizeof(tstring),"Hey, %s! \nYour account is registered.\nPlease enter the password to log in!",pName);
ShowPlayerDialog(playerid,Logindialog,DIALOG_STYLE_INPUT,"Lo g in",tstring,"Login","");
}
mysql_free_result();
OnDialogResponse
pawn Код:
if(dialogid == Regdialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,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];
new Query[140];
mysql_real_escape_string(inputtext, EscapedText);
format(Query,sizeof(Query),"INSERT INTO `users` (`Username`,`Password`) VALUES('%s','%s)",GetName(playerid),EscapedText);
mysql_query(Query);
SendClientMessage(playerid,-1,"You have been successfully registered!");
}
}
if(dialogid == Logindialog)
{
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid,Regdialog,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);
}
}
pawn Код:
stock LoadStats(playerid)
{
new pName[24],Query[80];
format(Query, sizeof(Query), "SELECT * FROM `users` WHERE `Username` = '%s' ", GetName(playerid));
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query, "|");
sscanf(Query, "e<p<|>s[24]s[23]i>", Info[playerid]);
mysql_free_result();
GivePlayerCash(playerid,Info[playerid][Money]);
return 1;
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60];
new Query[140];
mysql_real_escape_string(password, EscapedText);
format(Query,sizeof(Query),"SELECT * FROM `users` WHERE `Username` = '%s' AND `Password` = '%s'",GetName(playerid),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;
}