MySQL saving problem
#1

Hello,

I tried to create a Dynamic Door system, but the MySQL saving process doesn't work.

Here is the command:
Код:
CMD:createdoor(playerid, params[]) {
    if(playerVariables[playerid][pAdminLevel] >= 5) {
		new
	   		Float: floatPos[3];

		if(!strcmp(params, "Exterior", true)) {
	        GetPlayerPos(playerid, floatPos[0], floatPos[1], floatPos[2]);

	        SetPVarFloat(playerid, "pHeX", floatPos[0]);
	        SetPVarFloat(playerid, "pHeY", floatPos[1]);
	        SetPVarFloat(playerid, "pHeZ", floatPos[2]);

	        SetPVarInt(playerid, "hExt", 1);

	        SendClientMessage(playerid, COLOR_WHITE, "Dynamic Door exterior position configured.");
		} else if(!strcmp(params, "Interior", true)) {
            GetPlayerPos(playerid, floatPos[0], floatPos[1], floatPos[2]);

            SetPVarFloat(playerid, "pHiX", floatPos[0]);
            SetPVarFloat(playerid, "pHiY", floatPos[1]);
            SetPVarFloat(playerid, "pHiZ", floatPos[2]);

			SetPVarInt(playerid, "pHiID", GetPlayerInterior(playerid));
            SetPVarInt(playerid, "hInt", 1);

            SendClientMessage(playerid, COLOR_WHITE, "Dynamic Door interior position configured.");
		} else if(!strcmp(params, "Complete", true)) {
        	if(GetPVarInt(playerid, "hExt") != 1 || GetPVarInt(playerid, "hInt") != 1)
				return SendClientMessage(playerid, COLOR_GREY, "You haven't configured either the dynamic door exterior or interior. Creation attempt failed.");

			new
			    i,
           		labelString[96],
           		name[50];
           		
           		
      		mysql_query("INSERT INTO DynamicDoors (doorName) VALUES('(null)')");
			i = mysql_insert_id();

			if(isnull(dynamicDoor[i][dName])) {
				dynamicDoor[i][dExPos][0] = GetPVarFloat(playerid, "pHeX");
				dynamicDoor[i][dExPos][1] = GetPVarFloat(playerid, "pHeY");
				dynamicDoor[i][dExPos][2] = GetPVarFloat(playerid, "pHeZ");

				dynamicDoor[i][dIntPos][0] = GetPVarFloat(playerid, "pHiX");
   				dynamicDoor[i][dIntPos][1] = GetPVarFloat(playerid, "pHiY");
		    	dynamicDoor[i][dIntPos][2] = GetPVarFloat(playerid, "pHiZ");

				dynamicDoor[i][dExterior] = GetPlayerInterior(playerid);
				dynamicDoor[i][dInterior] = GetPVarInt(playerid, "pHiID");
			    
		    	format(name, sizeof(name), "Created by: %s", szPlayerName);
			    
		    	dynamicDoor[i][dName] = name;

				format(labelString, sizeof(labelString), "ID: %i \n%s", i, dynamicDoor[i][dName]);

				dynamicDoor[i][dLabelID] = CreateDynamic3DTextLabel(labelString, COLOR_YELLOW, dynamicDoor[i][dExPos][0], dynamicDoor[i][dExPos][1], dynamicDoor[i][dExPos][2], 100, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 10.0);
				dynamicDoor[i][dPickupID] = CreateDynamicPickup(1314, 23, dynamicDoor[i][dExPos][0], dynamicDoor[i][dExPos][1], dynamicDoor[i][dExPos][2], 0, -1, -1, 50);

				saveDoor(i);

				DeletePVar(playerid, "pHeX");
   				DeletePVar(playerid, "pHeY");
		    	DeletePVar(playerid, "pHeZ");
		    	DeletePVar(playerid, "pHiX");
		    	DeletePVar(playerid, "pHeY");
		    	DeletePVar(playerid, "pHeZ");
		    	DeletePVar(playerid, "pHiID");

				SetPlayerInterior(playerid, 0);
				SetPlayerPos(playerid, dynamicDoor[i][dExPos][0], dynamicDoor[i][dExPos][1], dynamicDoor[i][dExPos][2]);

				return SendClientMessage(playerid, COLOR_WHITE, "Dynamic Door created!");
			} else
				return SendClientMessage(playerid, COLOR_WHITE, "There are no available dynamic door slots left, sorry!");
		} else
		    return SendClientMessage(playerid, COLOR_GREY, SYNTAX_MESSAGE"/createdoor [exterior/interior/complete]");
	}
	return 1;
}
Here is the saveDoor(const id) function:
Код:
stock saveDoor(const id) {
	if(strlen(dynamicDoor[id][dName]) >= 1) {
		format(szLargeString, sizeof(szLargeString), "UPDATE DynamicDoors SET doorExPos1 = '%f', doorExPos2 = '%f', doorExPos3 = '%f', doorIntPos1 = '%f', doorIntPos2 = '%f', doorIntPos3 = '%f'", dynamicDoor[id][dExPos][0], dynamicDoor[id][dExPos][1], dynamicDoor[id][dExPos][2], dynamicDoor[id][dIntPos][0], dynamicDoor[id][dIntPos][1], dynamicDoor[id][dIntPos][2]);
		format(szLargeString, sizeof(szLargeString), "%s, doorExteriorID = '%d', doorInteriorID = '%d'", szLargeString, dynamicDoor[id][dExterior], dynamicDoor[id][dInterior]);
		format(szLargeString, sizeof(szLargeString), "%s, doorName = '%s', WHERE doorID = '%d'", szLargeString, dynamicDoor[id][dName], id);
		mysql_query(szLargeString);
	}
	else {
	    return false;
 	}
	return 1;
}
And that's what I see after I use the cmd in game in the MySQL table:




Does anyone have any idea? I tried some things but it didn't work properly. Also, I can only create 1 dynamic door, when I want to create a 2nd one it says "No slots left."
Reply
#2

Inverted commas should be placed around the fields that you wanna edit, the same applies to table names. So it's not just the values that you wanna input into the table that you put inverted commas around. Additionally, I would recommend you to split you queries into parts, rather than do it all at once. A fragment of my code:

Код:
format(query, sizeof(query), "UPDATE `houses` SET `Owner` = '%s', `Pos_x` = '%f', `Pos_y` = '%f', `Pos_z` = '%f' WHERE `id` = '%d'",DomInfo[domid][hOwner], DomInfo[domid][hPos_x], DomInfo[domid][hPos_y], DomInfo[domid][hPos_z],  domid);
	send_query(query);
Where 'houses' is ofc the table name and the other fields are records that are to be edited.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)