Insert To Mysql
#1

Code:
 CMD:createhouse(playerid, params[])
{
    if(gPlayerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_LIGHTRED, "You need to log in first.");
    if(PlayerInfo[playerid][pAdmin] >= 7)
	{
		new house[64],Float:pX,Float:pY,Float:pZ,string[128],PropertyString[256],query[500];
		if(sscanf(params, "s[64]", house)) return SendClientMessage(playerid, COLOR_GREY, "Syntax:{FFFFFF} /createhouse [exterior/interior/complete]");
	    if(strcmp(house,"exterior",true) == 0)
		{
		    GetPlayerPos(playerid, pX, pY, pZ);
			SetPVarFloat(playerid, "pHeX", pX);
        	SetPVarFloat(playerid, "pHeY", pY);
        	SetPVarFloat(playerid, "pHeZ", pZ);
			SetPVarInt(playerid, "hExt", 1);
			SendClientMessage(playerid, COLOR_YELLOW, "House exterior position configured.");
		}
		if(strcmp(house,"interior",true) == 0)
		{
		    GetPlayerPos(playerid, pX, pY, pZ);
			SetPVarFloat(playerid, "pHiX", pX);
        	SetPVarFloat(playerid, "pHiY", pY);
        	SetPVarFloat(playerid, "pHiZ", pZ);
			SetPVarInt(playerid, "pHiID", GetPlayerInterior(playerid));
			SetPVarInt(playerid, "pHiVW", housess+1);
        	SetPVarInt(playerid, "hInt", 1);
			SendClientMessage(playerid, COLOR_YELLOW, "House interior position configured.");
		}
		if(strcmp(house,"complete",true) == 0)
		{
		    if(GetPVarInt(playerid, "hExt") != 1 || GetPVarInt(playerid, "hInt") != 1)
				return SendClientMessage(playerid, COLOR_ERROR, "(Error){FFFFFF} You haven't configured either the house exterior or interior. Creation attempt failed.");

			new i = housess+1;
			mysql_format(SQL, query, sizeof(query), "INSERT INTO `houses` (`EnterX`, `EnterY`, `EnterZ`, `Price`) VALUES ('%f', '%f', '%f', '%d')", "x, y, z, price");
			mysql_tquery(SQL, query, "", "");

			HouseInfo[i][hID]                           = i;
	    	HouseInfo[i][hEntrancex]                    = GetPVarFloat(playerid, "pHeX");
			HouseInfo[i][hEntrancey]                    = GetPVarFloat(playerid, "pHeY");
		 	HouseInfo[i][hEntrancez]                    = GetPVarFloat(playerid, "pHeZ");
    		HouseInfo[i][hExitx]                        = GetPVarFloat(playerid, "pHiX");
    		HouseInfo[i][hExity]                        = GetPVarFloat(playerid, "pHiY");
    		HouseInfo[i][hExitz]                        = GetPVarFloat(playerid, "pHiZ");
    		format(HouseInfo[i][hOwner], 64, "AdmBot");
    		format(HouseInfo[i][hDiscription], 64, "House");
    		HouseInfo[i][hValue]						= 1000000;
    		HouseInfo[i][hHel]                          = 0;
    		HouseInfo[i][hMusic]						= 0;
    		HouseInfo[i][hInterior]                     = GetPVarInt(playerid, "pHiID");
    		HouseInfo[i][hLock]                         = 0;
    		HouseInfo[i][hOwned]                        = 1;
    		HouseInfo[i][hRent]                         = 5;
    		HouseInfo[i][hRentabil]                     = 1;
    		HouseInfo[i][hTakings]                      = 0;
    		HouseInfo[i][hLevel]                        = 10;
    		HouseInfo[i][hVirtual]                      = GetPVarInt(playerid, "pHiVW");

    		mysql_format(SQL, query, sizeof(query), "UPDATE `houses` SET `Entrancex`='%f',`Entrancey`='%f',`Entrancez`='%f',`Exitx`='%f',`Exity`='%f',`Exitz`='%f',`Interior`='%d',`Virtual`='%d' WHERE `ID`='%d'", HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez], HouseInfo[i][hExitx], HouseInfo[i][hExity], HouseInfo[i][hExitz], HouseInfo[i][hInterior], HouseInfo[i][hVirtual], i);
    		mysql_tquery(SQL, query, "", "");
    		mysql_format(SQL, query, sizeof(query), "UPDATE `users` SET `House`='%d' WHERE `name`='AdmBot'", i);
    		mysql_tquery(SQL, query, "", "");

    		DeletePVar(playerid, "pHeX");
		    DeletePVar(playerid, "pHeY");
		    DeletePVar(playerid, "pHeZ");
		    DeletePVar(playerid, "pHiX");
		    DeletePVar(playerid, "pHeY");
		    DeletePVar(playerid, "pHeZ");
		    DeletePVar(playerid, "pHiID");
		    DeletePVar(playerid, "pHiVW");
		    DeletePVar(playerid, "pExt");
		    DeletePVar(playerid, "pInt");
            Create3DTextLabel(PropertyString, 0x9C0000F7, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez], 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
			format(PropertyString, sizeof(PropertyString),"{FFFFFF}House {B40404}%d \n{B40404}This house is for sale(/buyhouse) ! \n{FFFFFF}Description: {B40404}%s \n{FFFFFF}Price: {B40404}$%s \n{FFFFFF}Level: {B40404}%d",i,HouseInfo[i][hDiscription],FormatNumber(HouseInfo[i][hValue]),HouseInfo[i][hLevel]);
			HouseLabel[i] = Create3DTextLabel(PropertyString, 0x9C0000F7, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez], 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, 0, 0, 0, 100.0);
			HouseLabel[i] = Create3DTextLabel(PropertyString, 0x008080FF, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez], 40.0, 0, 0);
			DestroyDynamicPickup(HousePickup[i]);
			HousePickup[i] = AddStaticPickup(1273, 23, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez]);

			SetPlayerInterior(playerid, 0);
			SetPlayerVirtualWorld(playerid, 0);
			SetPlayerPos(playerid, HouseInfo[i][hEntrancex], HouseInfo[i][hEntrancey], HouseInfo[i][hEntrancez]);
			housess++;
			format(string,sizeof(string),"House %d created!",i);
			SendClientMessage(playerid, COLOR_YELLOW, string);
		}
	}
	else return SendClientMessage(playerid, COLOR_LIGHTGREEN3, AdminOnly);
	return 1;
}
Houses dont insert in mysql. In mysql is inserted "House x x= 0 y = 0 z = 0 etc".
like this: https://i.imgur.com/GomoWoP.png
Reply
#2

You seem to be feeding mysql_format a string. Use it like this instead.

Code:
mysql_format(SQL, query, sizeof(query), "INSERT INTO `houses` (`EnterX`, `EnterY`, `EnterZ`, `Price`) VALUES ('%f', '%f', '%f', '%d')", x, y, z, price);
Also, why are the variables x, y and z when at the top of the command you create pX, pY and pZ? Are they defined and set somewhere else?

If that doesn't work, make sure the fields in the MySQL database aren't defined as integers
Reply
#3

Not working
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)