SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 04/10/2010, 10:27 PM   #1
almighty
Big Clucker
 
Join Date: Aug 2007
Posts: 164
Reputation: 0
Default Help with MYSQL, Avoid Dual Records?

Hey Guys... Me Again xD... Im triying to learn MYSQL.... Im using G-sTyLeZzZ Plugin...
im having issues with a register command im triying to make... i have this....

Code:
CMD:register(playerid,params[])
{
	new query[256];
	if(isnull(params)) return SendClientMessage(playerid,COLOR_SERVER_WARNING,"[USAGE]: /REGISTER [PASSWORD]");
	if(strlen(params) < 6) return SendClientMessage(playerid,COLOR_SERVER_WARNING,"[ERROR]: Password should contain at least 6 Characters!");
	mysql_real_escape_string(params,params);
	format(query,sizeof(query),"INSERT INTO `%s` (Username,Password) VALUES ('%s',md5('%s'))",SQL_TABLE,PName(playerid),params);
	mysql_query(query);
	if(!IsPlayerConnected(playerid)) return AvoidSync();
	mysql_store_result();
	if(mysql_affected_rows())
	{
		SendClientMessage(playerid,COLOR_SERVER,"Congratulations, You'r account is now registered!, Please Log In!");
		PA[playerid][Registered] = true;
	}
	else
	{
	    SendClientMessage(playerid,COLOR_SERVER_WARNING,"[ERROR]: Registration Failed!");
	}
	return 1;
}
The thing is... I was wondering.... Is there a way to avoid dual registry?... So people with the same name cant register?.... I have tried to register... after restarting the GM... an it creates the Player, but it increases the ID so...
__________________
"This... is the way the world ends..." - "May Talos Guide You" - "Close Shut the Jaws... Of Oblivion!" - "Revelation 2:16, I am Alpha and Omega, The Beginning and the end. I Will give unto him that is athirs from the fountain of water of life freely" - "Death its a preferable alternative to Comunism" - "Embrace Democracy or you will be eradicated!"
almighty is offline  
Old 04/10/2010, 10:35 PM   #2
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,016
Reputation: 409
Default Re: Help with MYSQL, Avoid Dual Records?

pawn Code:
new name[24];
mysql_escape_string(Pname(playerid), name);
format(query,sizeof(query),"SELECT * FROM `%s`  WHERE Username = %s",SQL_TABLE, name);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows > 0) return SendClientMessage(playerid,COLOR_SERVER_WARNING,"[ERROR]: This username is already registered!");
mysql_free_result();
That should do it .
__________________
[HiC]TheKiller is offline  
Old 04/10/2010, 10:52 PM   #3
almighty
Big Clucker
 
Join Date: Aug 2007
Posts: 164
Reputation: 0
Default Respuesta: Help with MYSQL, Avoid Dual Records?

Thanks... its working.... it seems... i saw the tutorial on you sig... gonna use it.... :P... if you dont mind me asking these, there are a few funtions i dont really get... like... the "mysql_real_escape_string"... What is it for?... or whats the result stored on Mysql_store_result?... also... The part were you do the mysql_num_rows... it checks if in the database, from the query, has been found rows?
__________________
"This... is the way the world ends..." - "May Talos Guide You" - "Close Shut the Jaws... Of Oblivion!" - "Revelation 2:16, I am Alpha and Omega, The Beginning and the end. I Will give unto him that is athirs from the fountain of water of life freely" - "Death its a preferable alternative to Comunism" - "Embrace Democracy or you will be eradicated!"
almighty is offline  
Old 05/10/2010, 01:41 AM   #4
[HiC]TheKiller
High-roller
 
Join Date: Mar 2008
Location: New Zealand
Posts: 3,016
Reputation: 409
Default Re: Respuesta: Help with MYSQL, Avoid Dual Records?

Quote:
Originally Posted by almighty View Post
Thanks... its working.... it seems... i saw the tutorial on you sig... gonna use it.... :P... if you dont mind me asking these, there are a few funtions i dont really get... like... the "mysql_real_escape_string"... What is it for?... or whats the result stored on Mysql_store_result?... also... The part were you do the mysql_num_rows... it checks if in the database, from the query, has been found rows?
MySQL_Escape_Query makes it so that players cannot SQL inject because if they do it could delete your whole table.

MySQL_Store_Result is just storing the information that you are trying to retrieve from the database.

MySQL_Num_Rows is checking how much rows the stored result returned. I made it more than 0 because if the mysql connection is down it's -1 and if there is no existing rows then it is 0.

For more information visit http://wiki.sa-mp.com/wiki/MySQL
__________________
[HiC]TheKiller is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Avoid Looping - Scripting Quesiton Daniel_June Help Archive 1 29/01/2010 02:08 PM
[MySQL]: How to avoid this ? Dreftas Help Archive 4 29/11/2009 10:39 AM
About bot records XpDeviL Help Archive 2 03/09/2009 06:47 AM
Count Array Records function raymy Help Archive 4 25/03/2009 01:27 PM


All times are GMT. The time now is 06:47 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.