What wrong with this load a save house system
#1

Well, I decided to put my houses in mysql database and i have ran in to some issues, It's not saving the houses in the database like it's suppose to be


The Save Houses
pawn Код:
forward SaveHouses();
public SaveHouses()
{
            new idx;
            new sql[512];
            while (idx < sizeof(HouseInfo))
            {
            format(sql, sizeof(sql), "UPDATE houses SET Houseowner='%s',HenterX=%f,HenterY=%f,HenterZ=%f,HexitX=%f,HexitY=%f,HexitZ=%f,HenterInt=%d,HenterWorld=%d,HousePrice=%d,HouseRentPrice=%d,HouseRentable=%d,HouseLocked=%d,HouseDrugs=%d,HouseMats=%d,HouseGun1=%d,HouseGunAmmo1=%d,HouseGun2=%d,HouseGun2=%d,HouseGun3=%d,HouseGun3=%d,HouseMoney=%d,HouseOwned=%d,HouseLevel=%d WHERE Id=%d",
            HouseInfo[idx][hId],
            HouseInfo[idx][hOwner],
            HouseInfo[idx][hEnterX],
            HouseInfo[idx][hEnterY],
            HouseInfo[idx][hEnterZ],
            HouseInfo[idx][hExitX],
            HouseInfo[idx][hExitY],
            HouseInfo[idx][hExitZ],
            HouseInfo[idx][EnterInterior],
            HouseInfo[idx][EnterWorld],
            HouseInfo[idx][hPrice],
            HouseInfo[idx][hRentPrice],
            HouseInfo[idx][hRentable],
            HouseInfo[idx][hLocked],
            HouseInfo[idx][hDrugs],
            HouseInfo[idx][hMaterials],
            HouseInfo[idx][hGun1],
            HouseInfo[idx][hGunAmmo1],
            HouseInfo[idx][hGun2],
            HouseInfo[idx][hGunAmmo2],
            HouseInfo[idx][hGun3],
            HouseInfo[idx][hGunAmmo3],
            HouseInfo[idx][hMoney],
            HouseInfo[idx][hOwned],
            HouseInfo[idx][hLevel]);
            idx++;
            mysql_query(sql);
            }
            return 1;
        }
This Hasn't been tested since i haven't been able to make them save to the database but here is my loadhouses
pawn Код:
forward LoadHouses();
public LoadHouses()
{
        new arrCoords[24][32];
        new sql[128];
        new row[512];
        format(sql, sizeof(sql), "SELECT COUNT(*) FROM houses");
        mysql_query(sql);
        mysql_store_result();
        mysql_fetch_row(row);
        totalhouses = strval(row);
        mysql_free_result();
        new idx = 0;
        while(idx < totalhouses)
        {
            format(sql, sizeof(sql), "SELECT * FROM houses WHERE Houseid = %d", idx);
            mysql_query(sql);
            mysql_store_result();
            if(mysql_num_rows() > 0)
            {
            strmid(HouseInfo[idx][hOwner], arrCoords[0], 0, strlen(arrCoords[0]), 255);
            HouseInfo[idx][hEnterX] = floatstr(arrCoords[1]);
            HouseInfo[idx][hEnterY] = floatstr(arrCoords[2]);
            HouseInfo[idx][hEnterZ] = floatstr(arrCoords[3]);
            HouseInfo[idx][hExitX] = floatstr(arrCoords[4]);
            HouseInfo[idx][hExitY] = floatstr(arrCoords[5]);
            HouseInfo[idx][hExitZ] = floatstr(arrCoords[6]);
            HouseInfo[idx][EnterInterior] = strval(arrCoords[7]);
            HouseInfo[idx][EnterWorld] = strval(arrCoords[8]);
            HouseInfo[idx][hPrice] = strval(arrCoords[9]);
            HouseInfo[idx][hRentPrice] = strval(arrCoords[10]);
            HouseInfo[idx][hRentable] = strval(arrCoords[11]);
            HouseInfo[idx][hLocked] = strval(arrCoords[12]);
            HouseInfo[idx][hDrugs] = strval(arrCoords[13]);
            HouseInfo[idx][hMaterials] = strval(arrCoords[14]);
            HouseInfo[idx][hGun1] = strval(arrCoords[15]);
            HouseInfo[idx][hGunAmmo1] = strval(arrCoords[16]);
            HouseInfo[idx][hGun2] = strval(arrCoords[17]);
            HouseInfo[idx][hGunAmmo2] = strval(arrCoords[18]);
            HouseInfo[idx][hGun3] = strval(arrCoords[19]);
            HouseInfo[idx][hGunAmmo3] = strval(arrCoords[20]);
            HouseInfo[idx][hMoney] = strval(arrCoords[21]);
            HouseInfo[idx][hOwned] = strval(arrCoords[22]);
            HouseInfo[idx][hLevel] = strval(arrCoords[23]);
            new string[128];
            if(HouseInfo[idx][hOwned] == 0) {
                new location[MAX_ZONE_NAME];
                Get2DZone(location, MAX_ZONE_NAME, HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ]);
                format(string, sizeof(string), "[House for sale]\nAddress: %d %s\nPrice: $%d\n Level: %d",idx,location,HouseInfo[idx][hPrice],HouseInfo[idx][hLevel]);
                housetext[idx] = Create3DTextLabel(string,COLOR_SPRINGGREEN,HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],40.0,0, 1);
            }
            else if(HouseInfo[idx][hOwned] == 1 && HouseInfo[idx][hRentable] == 0) {
                new location[MAX_ZONE_NAME];
                Get2DZone(location, MAX_ZONE_NAME, HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ]);
                format(string, sizeof(string), "[House]\nAdress: %d %s\n Owner:%s\n Level: %d", idx,location,HouseInfo[idx][hOwner],HouseInfo[idx][hLevel]);
                housetext[idx] = Create3DTextLabel(string,COLOR_GOLD,HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],40.0,0, 1);
            }
            else if(HouseInfo[idx][hOwned] == 1 && HouseInfo[idx][hRentable] == 1) {
                new location[MAX_ZONE_NAME];
                Get2DZone(location, MAX_ZONE_NAME, HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ]);
                format(string, sizeof(string), "[House]\nAdress: %d %s\nRent Price - $%d\n Owner:%s\n Level: %d", idx,location,HouseInfo[idx][hRentPrice],HouseInfo[idx][hOwner],HouseInfo[idx][hLevel]);
                housetext[idx] = Create3DTextLabel(string,COLOR_GOLD,HouseInfo[idx][hEnterX],HouseInfo[idx][hEnterY],HouseInfo[idx][hEnterZ],40.0,0, 1);
            }
            idx++;
            printf("%d Houses loaded from database", totalhouses);
        }
    }
    return 1;
}
Reply
#2

You need to put apostrophes around floats, as a example below:

pawn Код:
mysql_query("UPDATE Positions SET PosX = '0.000'");
Reply
#3

Quote:
Originally Posted by Carlton
Посмотреть сообщение
You need to put apostrophes around floats, as a example below:

pawn Код:
mysql_query("UPDATE Positions SET PosX = '0.000'");
Ok, i have done that but it's still not saving to the database I've set

pawn Код:
HenterX='%f'
And so on
Reply
#4

Did you enable the debug/log from your MySQL plugin? If so, please check out what's wrong in the query, and paste it in your next post.
Reply
#5

The mysql Log, Only where it does the houses

Код:
[08/08/10 04:35:09] Function: 'mysql_query' executed: "UPDATE houses SET Houseowner='',HenterX='0.000000',HenterY='0.000000',HenterZ='0.000000',HexitX='0.000000',HexitY='0.000000',HexitZ='0.000000',HenterInt=0,HenterWorld=0,HousePrice=0,HouseRentPrice=0,HouseRentable=0,HouseLocked=0,HouseDrugs=0,HouseMats=0,HouseGun1=0,HouseGunAmmo1=0,HouseGun2=0,HouseGun2=0,HouseGun3=0,HouseGun3=0,HouseMoney=0,HouseOwned=0,HouseLevel=0 WHERE Id=0" with result: "0".
No errors, I know it's not the commands since they all worked before i switched to mysql, It's just not writing the value
Reply
#6

anything?
Reply
#7

nothing?
Reply
#8

If you want to save a new one, you need to insert:
INSERT INTO table (column,column,column) VALUES ('value','value','value')
Reply
#9

Quote:
Originally Posted by r0b
Посмотреть сообщение
If you want to save a new one, you need to insert:
INSERT INTO table (column,column,column) VALUES ('value','value','value')
I have tried that all i get is errors in the mysq_log
This happens right when savehouses gets used
Код:
[08/09/10 06:20:43] Error (0): Could not execute query. 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 '1124710895','1105035264','0','0','0','0','0','100','0','0','0','0','0','0','0','' at line 1.

[08/09/10 06:20:43] Error (0): Could not execute query. 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 '1124710895','1105035264','0','0','0','0','0','100','0','0','0','0','0','0','0','' at line 1.
Here is the Insert into

pawn Код:
format(sql, sizeof(sql), "INSERT INTO property (Howner,Enterx,Enterz,Enterz,Exitx,Exity,Exitz,Hint,Hworld,Hprice,Rentprice,Hrentable,Hlocked,Hdrugs,Hmats,Hgun1,Hammo1,Hgun2,Hammo2,Hgun3,Hammo3,Hmoney,Howned,Hlevel) VALUES ('%s','$f','$f','$f','$f','$f','$f','%d,'%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
Reply
#10

HouseInfo[idx][hId] is the first in the list but it should be the last.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)