I can't get this code to work - House System
#1

So, I'm trying to create a house and insert it into the database, yet I'm getting errors, I've tried fixing them yet nothing freaking works.


Here's the code, I'd like an explanation why it doesn't work an how to fix it, thanks


pawn Код:
new query[180];

if(dialogid == DIALOG_SET_HOUSE_INTERIOR)
    {
        if(!response) return SendClientMessage(playerid, 0xFF0000FF, "You chose not to create any house and set an interior for it.");
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    SetPlayerInterior(playerid, 1);
                    SetPlayerVirtualWorld(playerid, 1000);
                    new Float:x, Float:y, Float:z;
                    new own = 0;
                    new ownr[MAX_PLAYER_NAME] = "ForSale";
                    GetPlayerPos(playerid, x, y, z);
                    mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, %f, %f, %f, %d, %d)", ownr, own, g_Price, x, y, z, 244.411987, 305.032989, 999.148437, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
                    mysql_pquery(g_Write, query, "OnHouseCreation_1", "d", playerid);
                    CreatePickup(1239, 23, x, y, z, -1);
                    SetTimerEx("HouseTimer_1", false, 1000, "d", playerid);
                }
            }
        }
        return 1;
    }  
    return 0;
}
Reply
#2

pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", ownr, own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Try this code, if it didn't work please show me your mysql.logs.
Reply
#3

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('%s', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", ownr, own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Try this code, if it didn't work please show me your mysql.logs.
Ah.. Doesn't work sadly.

Here's the error (Forgot to show it in the original post):

pawn Код:
[17:33:17] [ERROR] mysql_format - destination size is too small
[17:33:17] [ERROR] CMySQLQuery::Execute[OnHouseCreation_1] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
EDIT: Actually it works, lol..
Turns out that your syntax was right and I forgot to add a column called HouseOwner, like I added it I just didn't call it that...
Reply
#4

It seems like the problem in your ownr string, its null.
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('Forsale', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Also its not recommended to use ForSale name because some players can login with that name and he will be the owner of some houses.
Reply
#5

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
It seems like the problem in your ownr string, its null.
pawn Код:
mysql_format(g_Write, query, sizeof(query), "INSERT INTO houses (HouseOwner, Owned, Price, PosX, PosY, PosZ, ePosX, ePosY, ePosZ, InteriorID, VirtualWorld) VALUES ('Forsale', %d, %d,%f, %f, %f, 244.411987, 305.032989, 999.148437, %d, %d)", own, g_Price, x, y, z, GetPlayerInterior(playerid), GetPlayerVirtualWorld(playerid));
Also its not recommended to use ForSale name because some players can login with that name and he will be the owner of some houses.
What should I use instead then?

I only wrote forsale because I want to compare it later on when a player attempts to buy a house.
Reply
#6

Use something like FS because the player can't login with name lower than 3 letters.


EDIT: sorry just use a space on that string i forgot that the player can't login while he have spaces in his name use something like "For sale".
Reply
#7

Quote:
Originally Posted by SilentSoul
Посмотреть сообщение
Use something like FS because the player can't login with name lower than 3 letters.
Alright thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)