Saving mysql change
#1

Hello, I have a problem with my script, If I create a faction, she saved in the DB, but If I edit, the name for example, the modification does not occur in the DB


Code:
CMD:faction(playerid, params[])
{
	if (Player[playerid][AdminLevel] < 5) return SendClientMessage(playerid, COLOR_LIGHTRED, MSG_ERROR_PERMISSION), 1;
	static nom[24], scmd[128];
	if (sscanf(params, "s[24]S()[128]", nom, scmd))
	{
	    SendClientMessage(playerid, COLOR_GREEN, "{FF6347}Usage: {FFFFFF}/faction [actions]");
	    SendClientMessage(playerid, COLOR_LIGHTRED, "Actions: {FFFFFF}creer, edit, supprimer");
	    return 1;
	}

	if (!strcmp(nom, "creer", true))
	{
	 	static id = -1, type, name[32];

		if (sscanf(scmd, "ds[32]", type, name))
		{
			SendClientMessage(playerid, COLOR_GREEN, "{FF6347}Usage: {FFFFFF}/faction creer [type id] [nom de la faction]");
			SendClientMessage(playerid, COLOR_LIGHTRED, "Types:{FFFFFF} 1: POLICE | 2: JOURNALISTE | 3: GOUVERNEMENT | 4: GANG | 5: MAFIA | 6: DOJ | 7: PRISON" );
			return 1;
		}
		if (type < 1 || type > 7) return SendClientMessage(playerid, COLOR_LIGHTRED, "Type spйcifiй non valide. Les types factions vont de 1 а 7.");

		id = Faction_Create(name, type);
		
		if (id == -1) return SendClientMessage(playerid, COLOR_LIGHTRED, "Erreur: Le serveur a atteint la limite de faction.");
		SendClientMessageF(playerid, COLOR_LIGHTBLUE, "Vous avez crйй la faction ID: %d avec le nom: %s", id, name);
	}
	
	if (!strcmp(nom, "edit", true))
	{
		static id, type[24], string[128];

		if (sscanf(scmd, "ds[24]S()[128]", id, type, string))
		{
			SendClientMessage(playerid, COLOR_LIGHTRED, "/faction edit <id> <options>");
			SendClientMessage(playerid, COLOR_LIGHTRED, "OPTIONS: name, color, type, skins, locker, ranks, maxranks");
			return 1;
		}
		if ((id < 0 || id >= MAX_FACTIONS))
		return SendClientMessage(playerid, COLOR_LIGHTRED, "Vous avez specifiй un ID faction invalide.");

		if (!strcmp(type, "name", true))
		{
			new name[32];

			if (sscanf(string, "s[32]", name))
			return SendClientMessage(playerid, COLOR_LIGHTRED, "/faction edit <FactionID> name <NouveauNom>");

			format(FactionInfo[id][Namefaction], 32, name);

			FactionSave(id);
			//SendAdminAlert(COLOR_ADMINGROUP, "%s a ajustй le nom de faction ID: %d а \"%s\".", ReturnName(playerid), id, name);
		}
		else if (!strcmp(type, "type", true))
		{
			new typeint;

			if (sscanf(string, "d", typeint))
			{
				SendClientMessage(playerid, COLOR_LIGHTRED, "/faction edit <FactionID> type <FactionType>");
				SendClientMessage(playerid, COLOR_LIGHTRED, "[TYPES]:{FFFFFF} 1: Police | 2: Journaliste | 3: Medical | 4: Gouvernement | 5: Gang | 6: Mafia");
				return 1;
			}
			if (typeint < 1 || typeint > 7)
			return SendClientMessage(playerid, COLOR_LIGHTRED, "Type spйcifiй non valide. Les types vont de 1 а 6.");

			FactionInfo[id][Typefaction] = typeint;

			FactionSave(id);
			//SendAdminAlert(COLOR_ADMINGROUP, "%s a ajustй le type de la faction ID: %d а %d.", ReturnName(playerid), id, typeint);
		}
		
	}
	return 1;
}


Code:
//factions //faction
Faction_Create(name[], type)
{
	//new query[128];
	for (new i = 0; i != MAX_FACTIONS; i ++) /*if (!FactionInfo[i][Existfaction])*/
	{
		format(FactionInfo[i][Namefaction], 32, name);

		//FactionInfo[i][Existfaction] = 1;
		FactionInfo[i][Typefaction] = type;
		FactionInfo[i][Argentfaction] = 100000;

	//	mysql_query(dbhandle, "INSERT INTO `factions` (`Typefaction`) VALUES(0)", false, "OnFactionCreated", "d", i);

	   	new query[512];
	  	mysql_format(dbhandle, query, sizeof query, "INSERT INTO `factions` (`namefaction`, `typefaction`, `argentfaction`) VALUES ('%s', '%d', '%d')", FactionInfo[i][Namefaction], FactionInfo[i][Typefaction], FactionInfo[i][Argentfaction]);
	  	mysql_tquery(dbhandle, query, "OnFactionCreated", "d", i);

		return i;
	}
	return -1;
}


Code:
forward OnFactionCreated(factionid);
public OnFactionCreated(factionid)
{
	//if (factionid == -1 || !FactionInfo[factionid][Existfaction])
//	return 0;

	FactionInfo[factionid][Sqlfaction] = cache_insert_id();

	return 1;
}

FactionSave(factionid)
{
	new query[700];
	mysql_format(dbhandle, query, sizeof query, "UPDATE `factions` SET `namefaction` = %s, `typefaction` = %d, `argentfaction` = %d WHERE `sqlfaction` = %d LIMIT 1", FactionInfo[factionid][Namefaction], FactionInfo[factionid][Typefaction], FactionInfo[factionid][Argentfaction], FactionInfo[factionid][Sqlfaction]);
	mysql_tquery(dbhandle, query);

	return 1;
}
Reply
#2

PHP Code:
mysql_format(dbhandlequerysizeof query"UPDATE `factions` SET `namefaction` = '%s', `typefaction` = %d, `argentfaction` = %d WHERE `sqlfaction` = %d LIMIT 1"FactionInfo[factionid][Namefaction], FactionInfo[factionid][Typefaction], FactionInfo[factionid][Argentfaction], FactionInfo[factionid][Sqlfaction]);
    
mysql_tquery(dbhandlequery); 
Because strings must have single quotes around them
You have in the insert function but not into the save one
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)