SA-MP Forums Archive
Create a new Id - 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: Create a new Id (/showthread.php?tid=576684)



Create a new Id - DetoNater - 06.06.2015

When ever a new player registers the Id of new one is replaced in the old one

this is my register cmd, I want a new Id to be created when a new player is registered.


Код:
 MySQLregister(playerid, params[])
{
	new password[130];
	mysql_escape_string(params,password);
	new str[128];
    mysql_format(mysql,str,sizeof(str),"INSERT INTO `users` (`Name`, `Pass`, `ID`) VALUES ('%s', '%s', '%s')",PlayerName(playerid),password, NewFieldID[playerid]);
	mysql_query(mysql,str);
	//--------------------------------------------------
	SendLangMessage(playerid, _COLOR_YELLOW, "Account wurde erstellt:","Account was created:","Tu cuenta ha sido creada:");
	switch(Sprache[playerid])
	{
		case 0: format(str, sizeof(str), "Passwort: \"%s\"",password);
		case 1: format(str, sizeof(str), "Password: \"%s\"",password);
		case 2: format(str, sizeof(str), "Contrasena: \"%s\"",password);
	}
	SendClientMessage(playerid, _COLOR_GREEN, str);
	SendLangMessage(playerid, _COLOR_GREEN, "Du wurdest eingeloggt!","You are logged in!","Has iniciado sesi鏮!");
	GivePlayerCash(playerid,10000);
	GiveClanCash(playerid,10000);
	LoggedIn[playerid] = 1;
	mysql_format(mysql,str, sizeof(str), "SELECT * FROM `users` WHERE Name = '%s'",PlayerName(playerid));
	mysql_query(mysql,str);
    NewFieldID[playerid] = cache_insert_id();
    return 1;
}
The mysql have the Id field


Re: Create a new Id - DetoNater - 06.06.2015

-bump- need help utmost!


Re: Create a new Id - Kitten - 06.06.2015

Create a new row and define it as AUTO_INCREMENT it'll just add itself up.


Re: Create a new Id - CodeStyle175 - 06.06.2015

PHP код:
MySQLregister(playeridpassword[])
{
    new 
query[128];
    
mysql_format(mysql,query,sizeof(query),"INSERT INTO users(Name, Pass) VALUES ('%s', '%s')",
    
PlayerName(playerid),password);
    new 
Cache:cquery=mysql_query(mysql,query);
    
UserSQLID[playerid] = cache_insert_id();
    
cache_delete(cquery);
    
    
GivePlayerCash(playerid,10000);
    
GiveClanCash(playerid,10000);
    
LoggedIn[playerid] = 1;
    
SCM(playerid,-1,"You successfully registered yourself.");
    return 
1;




Re: Create a new Id - DetoNater - 06.06.2015

can you give me an auto_increment for my code, I'm a bit confused.


Re: Create a new Id - Konstantinos - 06.06.2015

CodeStyle175's code inserts a new row and it retrieves the ID which is set with AUTO INCREMENT in the table structure. If you haven't set auto increment for "ID" field, then do it (phpMyAdmin or any other) and modify it because it's not something we can "give" you.

PS: At least use always cache as you don't use threaded queries which is something I'd suggest you to do.