Mysql error
#1

hi all,

I'm having a little problem which i can't really find

The error:
Код:
[19:34:42] [DEBUG] mysql_query - connection: 1, query: "INSERT INTO `houses` `HouseX`=2354.739013, `HouseY`=558.069763, ", use_cache: true
[19:34:42] [DEBUG] CMySQLQuery::Execute - starting query execution
[19:34:42] [ERROR] CMySQLQuery::Execute - (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 '`HouseX`=2354.739013, `HouseY`=558.069763, `HouseZ`=7.781250, `HouseInterior`=1,' at line 1
The code:
pawn Код:
CMD:createhouse(playerid, params[])
{
    if(pInfo[playerid][pAdminLevel] < 5) return 0;
    new query[1500];
    new slot = GetEmptyHouse();
    if(slot == -1) return SendClientMessage(playerid, -1, "{FF0000}[ERROR]:{ffffff} Max houses reached");
    if(sscanf(params,"iiis[24]i", hInfo[slot][HouseValue], hInfo[slot][VehicleSlots], hInfo[slot][HouseInterior], hInfo[slot][HouseOwner], hInfo[slot][HouseOwned])) return SendClientMessage(playerid, COLOR_RED,"Syntax: /createhouse [Server value] [vehicle slots] [Interior] [Owner] [Owned (1 for yes, 0 for no)");
    GetPlayerPos(playerid,hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ]);
    hInfo[slot][SalePrice] = hInfo[slot][HouseValue];
    format(query,sizeof(query), "INSERT INTO `houses` `HouseX`=%f, `HouseY`=%f, `HouseZ`=%f, `HouseInterior`=%i, `HouseValue`=%i, `SalePrice`=%i, `VehicleSlots`=%i, `HouseOwner`='%s', `HouseOwned`='%s', `HouseRegion`='%s'", hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], hInfo[slot][HouseInterior], hInfo[slot][HouseValue], hInfo[slot][SalePrice], hInfo[slot][VehicleSlots], hInfo[slot][HouseOwner],hInfo[slot][HouseOwned],GetPlayerArea(playerid));
    mysql_query(dbHandle, query);
    hInfo[slot][HouseID] = cache_insert_id();
    hInfo[slot][loaded] = true;
    new lab[150];
    if(hInfo[slot][HouseOwned] == 0)
    {
        CreateDynamicMapIcon(hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], 31, 0, -1, -1, -1, 50.0, MAPICON_LOCAL);
        format(lab, sizeof(lab), "{00cc00}House for sale\n{ffff00}House owner: %s\nHouse Value: %i\nSelling Price: %i\nHouse slots: %i", hInfo[slot][HouseOwner], hInfo[slot][HouseValue], hInfo[slot][SalePrice], hInfo[slot][VehicleSlots]);
        hInfo[slot][houselabel] = CreateDynamic3DTextLabel(lab, COLOR_RED, hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
    }
    if(hInfo[slot][HouseOwned] == 1)
    {
        format(lab, sizeof(lab), "{00cc00}House owner: %s\n{ffff00}House Value: %i\nHouse slots: %i", hInfo[slot][HouseOwner], hInfo[slot][HouseValue], hInfo[slot][VehicleSlots]);
        hInfo[slot][houselabel] = CreateDynamic3DTextLabel(lab, COLOR_RED, hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], 100.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 100.0);
    }
    return 1;
}
Thanks in advance
Reply
#2

With your query which you have

pawn Код:
format(query,sizeof(query), "INSERT INTO `houses` `HouseX`=%f, `HouseY`=%f, `HouseZ`=%f, `HouseInterior`=%i, `HouseValue`=%i, `SalePrice`=%i, `VehicleSlots`=%i, `HouseOwner`='%s', `HouseOwned`='%s', `HouseRegion`='%s'", hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], hInfo[slot][HouseInterior], hInfo[slot][HouseValue], hInfo[slot][SalePrice], hInfo[slot][VehicleSlots], hInfo[slot][HouseOwner],hInfo[slot][HouseOwned],GetPlayerArea(playerid));
    mysql_query(dbHandle, query);

You need to first declare which table you are inserting into, in which you have done, then use brackets before listing each row/column, before then stating the values that will be stored in each of those rows.
For example
pawn Код:
format(query,sizeof(query), "INSERT INTO `houses` (`HouseX`, `HouseY`, `HouseZ`, `HouseInterior`, `HouseValue, `SalePrice`, `VehicleSlots, `HouseOwner`, `HouseOwned`, `HouseRegion`) VALUES('%f', '%f', '%f', '%i', '%i', '%i', '%i', '%s', '%s', '%s')", hInfo[slot][HouseX], hInfo[slot][HouseY], hInfo[slot][HouseZ], hInfo[slot][HouseInterior], hInfo[slot][HouseValue], hInfo[slot][SalePrice], hInfo[slot][VehicleSlots], hInfo[slot][HouseOwner],hInfo[slot][HouseOwned],GetPlayerArea(playerid));
    mysql_query(dbHandle, query);
Reply
#3

As Liam says your just missing brackets "INSERT INTO [table] () VALUES ()"
Reply
#4

well i changed it but still no luck for me although the error changed a bit

New error:
Код:
[20:26:33] [DEBUG] mysql_query - connection: 1, query: "INSERT INTO `houses` (`HouseX`, `HouseY`, `HouseZ`, `HouseInteri", use_cache: true
[20:26:33] [DEBUG] CMySQLQuery::Execute - starting query execution
[20:26:33] [ERROR] CMySQLQuery::Execute - (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 'SalePrice`, `VehicleSlots, `HouseOwner`, `HouseOwned`, `HouseRegion`) VALUES('23' at line 1
Reply
#5

Error fixed was missing a `
Reply
#6

Quote:
Originally Posted by LiamM
Посмотреть сообщение
You need to first declare which table you are inserting into, in which you have done, then use brackets before listing each row/column, before then stating the values that will be stored in each of those rows.
Sidenote: if all columns will be filled then they don't need to be specified individually. Although perhaps it is better to do so anyway, should the structure somehow change.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)