MYSQL problem
#1

Hello,

I have just learned MYSQL and read a lot of tutorials and (samp-wiki), its really good but IDK why it doesn't save my password and when I join with another name I see the LOGIN Dialog,

code:

Код:
CheckAccountExists(account[])
{
	new string[128];
    format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s'", account);
    mysql_query(string);

	mysql_store_result();

	new value;
	value = mysql_num_rows();
	mysql_free_result();
	return value;
}

explode(const sSource[], aExplode[][], const sDelimiter[] = " ", iVertices = sizeof aExplode, iLength = sizeof aExplode[]) //this isn't mine!
{
	new
		iNode,
		iPointer,
		iPrevious = -1,
		iDelimiter = strlen(sDelimiter);

	while(iNode < iVertices)
	{
		iPointer = strfind(sSource, sDelimiter, false, iPointer);

		if(iPointer == -1)
		{
			strmid(aExplode[iNode], sSource, iPrevious, strlen(sSource), iLength);
			break;
		}
		else
		{
			strmid(aExplode[iNode], sSource, iPrevious, iPointer, iLength);
		}

		iPrevious = (iPointer += iDelimiter);
		++iNode;
	}
	return iPrevious;
}

public OnPlayerRegister(playerid, password[])
{
	if(!AccountExists[playerid])
	{
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "Type Down Your Password To Continue(log-in)", "Register","Quit");
	}

	if(strlen(password) < 3)
		return GameTextForPlayer(playerid, "~r~Your Password Must be Atleast 3", 3000, 3);
	if(strlen(password) >= 32)
	    return GameTextForPlayer(playerid, "~g~Your Password Is Too Long", 3000, 3);

	CheckMySQL();

	new string[128];
	format(string, sizeof(string), "INSERT INTO Users (Name,Password) VALUES ('%s','%s')", UserStats[playerid][Name], UserStats[playerid][Password]);
	mysql_query(string);

    AccountExists[playerid] = 1;
	SendClientMessage(playerid, GREEN, "Your account has been created, please login now!");
	OnPlayerLogin(playerid, password);
	return 1;
}

public OnPlayerLogin(playerid, password[])
{
 	if(AccountExists[playerid]) return ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Type Down Your Password To Continue(log-in)", "Log-in","Quit");
 	
	CheckMySQL();

    new string[128];
	format(string, sizeof(string), "SELECT * FROM Users WHERE Name = '%s' AND Password = '%s'", UserStats[playerid][Name], UserStats[playerid][Password]);
	mysql_query(string);
	mysql_store_result();

	if(!mysql_num_rows())
		return GameTextForPlayer(playerid, "~n~~n~~r~Incorrect password!", 3000, 3);

	new row[128]; 
	new field[4][32];

	mysql_fetch_row_format(row, "|");
	explode(row, field, "|");
	mysql_free_result();
	
	UserStats[playerid][Name] = strval(field[0]);
	format(UserStats[playerid][Password], 32, "%s", field[1]);
 	UserStats[playerid][Admin] = strval(field[2]);
 	UserStats[playerid][Money] = strval(field[3]);

 	GivePlayerMoney(playerid, UserStats[playerid][Money]);

	format(string, sizeof(string), "Welcome back %s, you are now logged in!", UserStats[playerid][Name]);
    SendClientMessage(playerid, GREEN, string);
    
    PlayerLogged[playerid] = 1;
    TogglePlayerControllable(playerid, false);
    return 1;
}

SavePlayer(playerid)
{
	if(!PlayerLogged[playerid])
		return 0;
		
    UserStats[playerid][Money] = GetPlayerMoney(playerid);
    UserStats[playerid][Admin] = UserStats[playerid][Admin];
	CheckMySQL();
   	new string[256];
    format(string, sizeof(string), "UPDATE Users SET Password='%s',Admin='%d',Money='%d' WHERE Name='%s'", UserStats[playerid][Password], UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Name]);
    mysql_query(string);
    return 1;
}
so pelase if there any thing wrong, not made good, tell me please : ) thank you!
Reply


Messages In This Thread
MYSQL problem - by Youice - 06.06.2012, 21:38
Re: MYSQL problem - by Youice - 06.06.2012, 21:52
Re: MYSQL problem - by Mandrakke - 06.06.2012, 22:11
Re: MYSQL problem - by Youice - 06.06.2012, 22:16
Re: MYSQL problem - by Mandrakke - 06.06.2012, 22:39
Re: MYSQL problem - by Youice - 06.06.2012, 22:42
Re: MYSQL problem - by Youice - 06.06.2012, 23:17
Re: MYSQL problem - by Youice - 07.06.2012, 20:07
Re: MYSQL problem - by HuSs3n - 07.06.2012, 20:11
Re: MYSQL problem - by Youice - 07.06.2012, 23:13

Forum Jump:


Users browsing this thread: 2 Guest(s)