15.05.2012, 22:50
I have a problem in my SQL.
Here is the SQL things that I have now:
Thanks!
Here is the SQL things that I have now:
pawn Код:
public OnPlayerConnect(playerid)
{
new Query[80], string[164];
format(Query,sizeof(Query),"SELECT `Username` FROM `Users` WHERE `Username` = '%s' LIMIT 1",pName(playerid));
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
format(string,sizeof(string),"Welcome back to 'Server Name' %s\nYou have got an account here\nPlease enter the password to login!",pName(playerid));
ShowPlayerDialog(playerid,1,DIALOG_STYLE_INPUT,"Login",string,"Login","Exit");
}
else
{
format(string,sizeof(string),"Welcome to 'Server Name' %s\nIt seems that your account isn't registered.\nPlease enter a password to register.",pName(playerid));
ShowPlayerDialog(playerid,0,DIALOG_STYLE_INPUT,"Register",string,"Register","Exit");
}
mysql_free_result();
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case 0:
{
if(!response) Kick(playerid);
else
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT,"Register","Welcome to 'Server Name' %s\nIt seems that your account isn't registered.\nPlease enter a password to register.","Register","Exit");
}
else
{
new EscapedText[60];
new Query[256];
mysql_real_escape_string(inputtext, EscapedText);
format(Query,sizeof(Query),"INSERT INTO `Users` (Username,Password,Money,AdminLevel,Banned,Score) VALUES ('%s','%s','0','0','0','0')",pName(playerid),EscapedText);
mysql_query(Query);
SendClientMessage(playerid,WHITE,"You have been successfully registered!");
}
}
case 1:
{
if(!response) Kick(playerid);
if(strlen(inputtext) == 0)
{
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT,"Login","Welcome back to 'Server Name' %s\nYou have got an account here\nPlease enter the password to login!","Login","Exit");
}
else
{
LoginPlayer(playerid,inputtext);
}
}
}
}
stock LoginPlayer(playerid,const password[])
{
new EscapedText[60], Query[256];
mysql_real_escape_string(password, EscapedText);
format(Query,sizeof(Query),"SELECT * FROM `Users` WHERE `Username` = '%s' AND `Password` = '%s'",pName(playerid),EscapedText);
mysql_query(Query);
mysql_store_result();
if(mysql_num_rows() != 0)
{
LoadStats(playerid);
}
else
{
SendClientMessage(playerid,WHITE,"You have entered an incorrect password and have been kicked as a result.");
Kick(playerid);
}
mysql_free_result();
return 1;
}
stock LoadStats(playerid)
{
new Query[256];
format(Query, sizeof(Query), "SELECT * FROM `Users` WHERE `Username` = '%s' ", pName(playerid));
mysql_query(Query);
mysql_store_result();
mysql_fetch_row_format(Query, "|");
sscanf(Query, "e<p<|>s[24]s[23]iiii>", Player[playerid]);
mysql_free_result();
GivePlayerMoney(playerid, Player[playerid][Money]);
Player[playerid][AdminLevel] = Player[playerid][AdminLevel];
SavePInfo(playerid);
if(Player[playerid][Banned] == 1)
{
SendClientMessage(playerid, WHITE, "You have been banned from this server! Please make a ban appeal on "FORUM".");
SavePInfo(playerid);
Kick(playerid);
return 0;
}
return 1;
}
stock SavePInfo(playerid)
{
new Query[256];
format(Query, sizeof(Query), "UPDATE `Users` SET `Money` = %d, `AdminLevel` = %d, `Banned` = %d, `Score` = %d WHERE `user` = '%s'",
Player[playerid][Money],
Player[playerid][AdminLevel],
Player[playerid][Banned],
Player[playerid][Score],
pName(playerid));
mysql_query(Query);
}