SA-MP Forums Archive
MYSQL problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MYSQL problem (/showthread.php?tid=348834)



MYSQL problem - Youice - 06.06.2012

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!


Re: MYSQL problem - Youice - 06.06.2012

any respond?


Re: MYSQL problem - Mandrakke - 06.06.2012

I see no syntax errors, put it somewhere into your script and paste the console output here;

pawn Код:
public OnQueryError(errorid, error[], resultid, extraid, callback[], query[], connectionHandle)
{
    printf("MySQL Error: %d %s %d %d %s %s %d", errorid, error, resultid, extraid, callback, query, connectionHandle);
    return 1;
}



Re: MYSQL problem - Youice - 06.06.2012

Thanks for your help but its the same problem


Re: MYSQL problem - Mandrakke - 06.06.2012

lol, I said to you to paste the code in to your script and paste the errors here.


Re: MYSQL problem - Youice - 06.06.2012

Quote:
Originally Posted by Mandrakke
Посмотреть сообщение
lol, I said to you to paste the code in to your script and paste the errors here.
lol, I have already did that and no errors showed up


Re: MYSQL problem - Youice - 06.06.2012

any help?!


Re: MYSQL problem - Youice - 07.06.2012

sorry for triple post, but can I know a solution?


Re: MYSQL problem - HuSs3n - 07.06.2012

so where do you use CheckAccountExists ?
you need to show us more of your code


Re: MYSQL problem - Youice - 07.06.2012

Okay

Код:
public OnPlayerConnect(playerid)
{
       //after some codes
	if(CheckAccountExists(UserStats[playerid][Name])) AccountExists[playerid] = 1;
	else AccountExists[playerid] = 0;
	
	AccountExists[playerid] = 0;
	return 1;
}