SA-MP Forums Archive
MySQL not saving - 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 not saving (/showthread.php?tid=627575)



MySQL not saving - AndreiWow - 29.01.2017

Код:
stock SavePlayerAccount(playerid)
{
	new DB_Query[1024];
	
	new
		   	Float:x,
		    Float:y,
			Float:z
		;
		
		
	if(PlayerInfo[playerid][LoggedIn] == 1)
	{
	    GetPlayerPos(playerid,x,y,z);
		PlayerInfo[playerid][pPos_x] = x;
		PlayerInfo[playerid][pPos_y] = y;
		PlayerInfo[playerid][pPos_z] = z;
	
	    mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `PASSWORD` = '%s', `SCORE` = '%d', `KILLS` = '%d', `CASH` = '%d', `DEATHS` = '%d', `Admin` = '%d'"
		, PlayerInfo[playerid][pPass], PlayerInfo[playerid][Score], PlayerInfo[playerid][Kills], PlayerInfo[playerid][pCash], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][pAdmin]);
		mysql_tquery(Database, DB_Query);
		
		mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = '%d', `Age` = '%d', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f', `Skin` = '%d', `Job` = '%d', `AccLock` = '%d'"
		, PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccLock]);
	    mysql_tquery(Database, DB_Query);
	}

	return 1;
}
and when the player disconnect:
Код:
SavePlayerAccount(playerid);
It doesn't work.


Also this is not working:
Код:
case DIALOG_EMAIL:
		{
		    if(response)
		    {
		        new DB_Query[225];
		        new iemail = strval(inputtext);
		        PlayerInfo[playerid][pEmail] = iemail;
				mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `email` = '%s'"
				, PlayerInfo[playerid][pEmail]);
				mysql_tquery(Database, DB_Query);
				
				SendClientMessage(playerid, COLOR_GREEN, "Email set succesfully! Moving onto the next part, gender!");
				
				ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_MSGBOX, "{FFA500}GENDER", "{FFFFFF}Are you a boy or a girl?\n\n", "BOY", "GIRL");
			}
		}
The email is not saving



I solved with others but the email is not saving, any idea why?


Re: MySQL not saving - Vince - 29.01.2017

Please find a reputable site to learn SQL. You don't have a WHERE-clause in any of your queries.


Re: MySQL not saving - X337 - 29.01.2017

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
Код:
stock SavePlayerAccount(playerid)
{
	new DB_Query[1024];
	
	new
		   	Float:x,
		    Float:y,
			Float:z
		;
		
		
	if(PlayerInfo[playerid][LoggedIn] == 1)
	{
	    GetPlayerPos(playerid,x,y,z);
		PlayerInfo[playerid][pPos_x] = x;
		PlayerInfo[playerid][pPos_y] = y;
		PlayerInfo[playerid][pPos_z] = z;
	
	    mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `PASSWORD` = '%s', `SCORE` = '%d', `KILLS` = '%d', `CASH` = '%d', `DEATHS` = '%d', `Admin` = '%d'"
		, PlayerInfo[playerid][pPass], PlayerInfo[playerid][Score], PlayerInfo[playerid][Kills], PlayerInfo[playerid][pCash], PlayerInfo[playerid][Deaths], PlayerInfo[playerid][pAdmin]);
		mysql_tquery(Database, DB_Query);
		
		mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `Sex` = '%d', `Age` = '%d', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f', `Skin` = '%d', `Job` = '%d', `AccLock` = '%d'"
		, PlayerInfo[playerid][pSex], PlayerInfo[playerid][pAge], PlayerInfo[playerid][pPos_x], PlayerInfo[playerid][pPos_y], PlayerInfo[playerid][pPos_z], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pTeam], PlayerInfo[playerid][pAccLock]);
	    mysql_tquery(Database, DB_Query);
	}

	return 1;
}
Is there any error message on your mysql log? Also, you need to add WHERE clause on your queries above to make it only update a single player stats. Otherwise, every data inside USERS table will be updated too.

Quote:
Originally Posted by AndreiWow
Посмотреть сообщение
Also this is not working:
Код:
case DIALOG_EMAIL:
		{
		    if(response)
		    {
		        new DB_Query[225];
		        new iemail = strval(inputtext);
		        PlayerInfo[playerid][pEmail] = iemail;
				mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USERS` SET `email` = '%s'"
				, PlayerInfo[playerid][pEmail]);
				mysql_tquery(Database, DB_Query);
				
				SendClientMessage(playerid, COLOR_GREEN, "Email set succesfully! Moving onto the next part, gender!");
				
				ShowPlayerDialog(playerid, DIALOG_SEX, DIALOG_STYLE_MSGBOX, "{FFA500}GENDER", "{FFFFFF}Are you a boy or a girl?\n\n", "BOY", "GIRL");
			}
		}
The email is not saving
Why are you converting an email to integer?
Код:
new iemail = strval(inputtext);
And, you need to use '%e' to escape string instead of '%s' in query above as it's injectable. And same as above, you need to add WHERE clause in that query.


Re: MySQL not saving - AndreiWow - 29.01.2017

Quote:
Originally Posted by X337
Посмотреть сообщение
Is there any error message on your mysql log? Also, you need to add WHERE clause on your queries above to make it only update a single player stats. Otherwise, every data inside USERS table will be updated too.



Why are you converting an email to integer?
Код:
new iemail = strval(inputtext);
And, you need to use '%e' to escape string instead of '%s' in query above as it's injectable. And same as above, you need to add WHERE clause in that query.
I fixed the WHERE and injection after I posted this, still I don't know how to save that email, if I use iemail[36] = inputtext I will get a error..


Re: MySQL not saving - ISmokezU - 29.01.2017

Did you just ignored Vince? Who just told you exactly what to do to fix your problem? SERIOUSLY?


Re: MySQL not saving - X337 - 29.01.2017

You need to format them, you can use format() or strcat().
Код:
format(PlayerInfo[playerid][pEmail], 128, "%s", inputtext);



Re: MySQL not saving - AndreiWow - 29.01.2017

Quote:
Originally Posted by ISmokezU
Посмотреть сообщение
Did you just ignored Vince? Who just told you exactly what to do to fix your problem? SERIOUSLY?
He said that I was missing WHERE, and I said that I added it after I posted this topic.


Re: MySQL not saving - ISmokezU - 29.01.2017

Then Post the edited Code.