[Tutorial] Easy MySQL Register/Login system!
#21

Nice way of setting up man, its a lot cleaner than the way i was doing it.

Just one thing. There isnt really much point to do this

Code:
SavePlayer(playerid)
{
	if(!PlayerLogged[playerid])
		return 0;

    	UserStats[playerid][Money] = GetPlayerMoney(playerid);
    

	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;
}
Your much better off just updating what you need to update. Its not like their password ever changes while they are logged in unless your going to add a change password option or something.

My Way
Code:
SavePlayer(playerid)
{
	if(!PlayerLogged[playerid])
		return 0;

    	UserStats[playerid][Money] = GetPlayerMoney(playerid);
    

	CheckMySQL();
    
    	new string[256];
    	format(string, sizeof(string), "UPDATE `users` SET `admin`='%d', `money`='%d' WHERE `name`='%s'", UserStats[playerid][Admin], UserStats[playerid][Money], UserStats[playerid][Name]);
    	mysql_query(string);
    	return 1;
}
Just thought id let ya know =D
Reply
#22

Quote:
Originally Posted by Martin_Santiago
View Post
Nice way of setting up man, its a lot cleaner than the way i was doing it.

Just one thing. There isnt really much point to do this

Your much better off just updating what you need to update. Its not like their password ever changes while they are logged in unless your going to add a change password option or something.

My Way

Just thought id let ya know =D
Yes thanks,
I always had it like that, but for the tutorial I implemented the password variable somehow, lol.
Reply
#23

Help please?

Reply
#24

Download VS9 version in the topic of the mysql plugin, otherwise update Net. Framework (I think).
Reply
#25

For me all works fine! Just started to learn mysql system and this tutorial is exactly what I need.
Reply
#26

Immah sound stupid right now, but if i wanted to change to dialog, how do i do this correctly, i attempted and failed.
Reply
#27

That's hardly bugged mate, I register and when I rejoin and I try to login it says I'm not registered.
Reply
#28

Its not bugged then, you just messed up with the database im guessing
Reply
#29

erm i need help with it saving skins. i tried it but it doesnt.
Reply
#30

got it.
my comment for the tut:
SIMPLY PERFECT!!!

my request to add:
save data of different tables and not only users(stats maybe?(having a hard time figuring it out))
Reply
#31

Quote:
Originally Posted by Delux13
View Post
That's hardly bugged mate, I register and when I rejoin and I try to login it says I'm not registered.
+1

Same here.
Reply
#32

Code:
SavePlayer(playerid)
{
	if(!PlayerLogged[playerid])
		return 0;

    	UserStats[playerid][Money] = GetPlayerMoney(playerid);
    

	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;
}
I am having some issues with the code above. I tried adding more .. but I get thess errors:

Code:
C:\SA-MP servers\The Roleplay Server\gamemodes\MySQL.pwn(1183) : error 075: input line too long (after substitutions)
C:\SA-MP servers\The Roleplay Server\gamemodes\MySQL.pwn(1184) : error 037: invalid string (possibly non-terminated string)
C:\SA-MP servers\The Roleplay Server\gamemodes\MySQL.pwn(1184) : error 017: undefined symbol "UPDATE"
C:\SA-MP servers\The Roleplay Server\gamemodes\MySQL.pwn(1184) : error 029: invalid expression, assumed zero
C:\SA-MP servers\The Roleplay Server\gamemodes\MySQL.pwn(1184) : fatal error 107: too many error messages on one line
I know this has something to do with .. too many charactars/ being too long inside the format function, but I'm no mastermind and can't figure out how to fix it currently. I know it has to be shortened to fix it probably, but I need all of them.
my code:

Code:
stock SavePInfo(playerid)
{
	if(GetPVarInt(playerid, "LoggedIN") == 1)
	{
		new Query[600];

		format(Query, sizeof(Query), "UPDATE `playerinfo` SET `kills` = %d, `deaths` = %d, `money` = %d, `Level` = %d, `Last Pos X` = %f, `Last Pos Y` = %f, `Last Pos Z` = %f, `Interior` = %d, `PMstatus` = %d, `Phonenumber` = %d, `Strength` = %d, `Jailtime` = %d, `Prisontime` = %d, `FactionID` = %d, `FactionRank` = %d, `FactionName` = %s, `RadioFreq` = %d, `PaycheckTime` = %d, `Gun0` = %d, `Gun1` = %d, `Gun2` = %d, `Gun3` = %d, `Gun4` = %d WHERE `user` = '%s'", // Also remember to update this...

		PVar[playerid][pKills],
		PVar[playerid][pDeaths],
		GetPlayerMoney(playerid),
		PVar[playerid][pAdminLevel],
		PVar[playerid][pLastX],
		PVar[playerid][pLastY],
		PVar[playerid][pLastZ],
		GetPlayerInterior(playerid),
		PVar[playerid][pPMstatus],
		PVar[playerid][pPhoneNumber],
		PVar[playerid][pStrentgh],
		PVar[playerid][pJailtime],
		PVar[playerid][pPrisontime],
		PVar[playerid][pFaction],
		PVar[playerid][pFactionRank],
		PVar[playerid][pFactionName],
		PVar[playerid][pRadioFrequency],
		PVar[playerid][pPaycheckTime],
		PVar[playerid][pGun0],
		PVar[playerid][pGun1],
		PVar[playerid][pGun2],
		PVar[playerid][pGun3],
		PVar[playerid][pGun4],
		pName(playerid));
		
		new Query2[600];
		format(Query, sizeof(Query), "UPDATE `playerinfo` SET `Ammo0` = %d, `Ammo1` = %d, `Ammo2` = %d, `Ammo3` = %d, `Ammo4` = %d, `IDnumber` = %d, `CarKey1` = %d, `Carkey2` = %d, `Carkey3` = %d,`WeaponLicense` = %d, `DrivingLicense` = %d, `Origin` = %d, `Sex` = %d, `BankPin` = %d, `Housekey1` = %d, `Housekey2` = %d, `Housekey3` = %d, `Bizkey1` = %d, `Bizkey2` = %d, `Bizkey3` = %d, `Rentkey` = %d, `Job` = %d, `Phonecontact1` = %d, `Phonecontact2` = %d, `Phonecontact3` = %d, `Phonecontact4` = %d WHERE `user` = '%s'", // Also remember to update this...
		
		PVar[playerid][pAmmo0],
		PVar[playerid][pAmmo1],
		PVar[playerid][pAmmo2],
		PVar[playerid][pAmmo3],
		PVar[playerid][pAmmo4],
		PVar[playerid][pIDnumber],
		PVar[playerid][pCarkey1],
		PVar[playerid][pCarkey2],
		PVar[playerid][pCarkey3],
		PVar[playerid][pWeaponLicense],
		PVar[playerid][pDrivingLicense],
		PVar[playerid][pOrigin],
		PVar[playerid][pSex],
		PVar[playerid][pBankpin],
		PVar[playerid][pHousekey1],
		PVar[playerid][pHousekey2],
		PVar[playerid][pHousekey3],
		PVar[playerid][pBizkey1],
		PVar[playerid][pBizkey2],
		PVar[playerid][pBizkey3],
		PVar[playerid][pRentkey],
		PVar[playerid][pJob],
		PVar[playerid][pPhoneContact1],
		PVar[playerid][pPhoneContact2],
		PVar[playerid][pPhoneContact3],
		PVar[playerid][pPhoneContact4],
		pName(playerid));
		
		new Query3[600];

		format(Query3, sizeof(Query3), "UPDATE `playerinfo` SET , `Phonecontact5` = %d, `Phonecontact6` = %d, `Phonecontact7` = %d, `Phonecontact8` = %d, `Phonecontact9` = %d, `Phonecontact10` = %d, `Phonecontact1` = %d, `Phonecontact11` = %d, `Phonecontact12` = %d, `Phonecontact13` = %d, `Phonecontact14` = %d, `Phonecontact15` = %d, `Jobcheckpoints` = %d, `Accent` = %d, `Virtualworld` = %d WHERE `user` = '%s'", // Also remember to update this...
		
		PVar[playerid][pPhoneContact5],
		PVar[playerid][pPhoneContact6],
		PVar[playerid][pPhoneContact7],
		PVar[playerid][pPhoneContact8],
		PVar[playerid][pPhoneContact9],
		PVar[playerid][pPhoneContact10],
		PVar[playerid][pPhoneContact11],
		PVar[playerid][pPhoneContact12],
		PVar[playerid][pPhoneContact13],
		PVar[playerid][pPhoneContact14],
		PVar[playerid][pPhoneContact15],
		PVar[playerid][pJobCheckpoints],
		PVar[playerid][pAccent],
		PVar[playerid][pVirtualWorld],
		pName(playerid));

		mysql_query(Query);
		mysql_query(Query2);
		mysql_query(Query3);
		mysql_free_result();
		return 1;
	}
	else return 0;
}
Reply
#33

What about Floats? In the loading system.
Reply
#34

I did it, but when i'm connected to my server, i have absolutely no message from your script

And if i do /register it does nothing

i'm kinda lost
Reply
#35

is it secured of injecting?
Reply
#36

this is just the worse... i can code in C++ and create my own scripts just fine, but when it comes to pawn..
well..
i fucking hate pawn..
Reply
#37

Uhm, any help about the id? I mean, iv put on the table a column(idk if its a column) which was ids which it auto increments, but i dont know how to apply that to the sv =S, anyways, very useful tut. =)
Reply
#38

It's not working!
-When I enter the server and type /register (it doesn't matter did I type password or no) it tells me that I'm already registered!
-When I login , I can do it with any password ! (for an example : I enter the server and type /login 1234 it shows me message that I'm succesfully logged in! When I restart the server and enter it again and type /login 123456 it again shows me that I'm succesfully logged in).
-Also must it save the money ? Before restarting the server I had about 20k $ and when I restarted the server I had 0$.. (Is it not saving the data in database or I didn't make as it's shown ?
Reply
#39

error 017: undefined symbol "mysql_query"

Only "mysql_query" ,other functions work!!
I am using R7 Windows Version of MySQL.
Reply
#40

Quote:
Originally Posted by Yashas
View Post
error 017: undefined symbol "mysql_query"

Only "mysql_query" ,other functions work!!
I am using R7 Windows Version of MySQL.
Change with older plugin R5 or R6
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)