[Ajuda] Pq с entra um novo registro MYSQL casa
#1

Em DINI todo o sistema de casa funcionava perfeito, mas em mysql nгo consigo salvar as casas que eu crio no jogo, to tentando fazer com base num tutorial gringo q eu vi de sistema de login/registro

Nem quando eu crio a casa:
pawn Код:
format(query, sizeof(query), "INSERT INTO houses SET ID = %d, InPosX = %f, InPosY = %f, InPosZ = %f, OutPosX = %f, OutPosY = %f, OutPosZ = %f, World = %d, Price = %d, Owner = %d, Dono = '%s', Money = %d, Maconha = %d, FHQ = %d, Interior = %d",
            HouseInfo[houseid][ID], HouseInfo[houseid][InPosX], HouseInfo[houseid][InPosY], HouseInfo[houseid][InPosZ], HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ], HouseInfo[houseid][World], HouseInfo[houseid][Price], HouseInfo[houseid][Owner], HouseInfo[houseid][Locked], HouseInfo[houseid][Dono], HouseInfo[houseid][Money], HouseInfo[houseid][Maconha], HouseInfo[houseid][FHQ], HouseInfo[houseid][Interior] );
pawn Код:
CMD:makehouse(playerid, params[]) {
        if(admin[playerid] < 6) return 0;
        new houseid, type;
        new query[1024];
        new string[80];
        if(sscanf(params,"ii", houseid, type)) {
            SendClientMessage(playerid, -1, "Use: /makehouse [houseid] [type]");
            SendClientMessage(playerid, -1, "types: 1-pequena 2-media 3-grande 4-mansгo 5-vip");
            return 1;
        }
        switch( type ) {
            case 1: { // Pequena
                HouseInfo[houseid][InPosX] = 223.20;
                HouseInfo[houseid][InPosY] = 1287.08;
                HouseInfo[houseid][InPosZ] = 1082.14;
                HouseInfo[houseid][Interior] = 1;
                HouseInfo[houseid][Price] = 500000;
            }
            case 2: { // media
                HouseInfo[houseid][InPosX] = 2365.31;
                HouseInfo[houseid][InPosY] = -1135.60;
                HouseInfo[houseid][InPosZ] = 1050.88;
                HouseInfo[houseid][Interior] = 8;
                HouseInfo[houseid][Price] = 3000000;
            }
            case 3: { // grande
                HouseInfo[houseid][InPosX] = 446.99;
                HouseInfo[houseid][InPosY] = 1397.07;
                HouseInfo[houseid][InPosZ] = 1084.30;
                HouseInfo[houseid][Interior] = 2;
                HouseInfo[houseid][Price] = 10000000;
            }
            case 4: { // mansгo
                HouseInfo[houseid][InPosX] = 2196.85;
                HouseInfo[houseid][InPosY] = -1204.25;
                HouseInfo[houseid][InPosZ] = 1049.02;
                HouseInfo[houseid][Interior] = 6;
                HouseInfo[houseid][Price] = 100000000;

            }
            case 5: { // VIP
                HouseInfo[houseid][InPosX] = 140.17;
                HouseInfo[houseid][InPosY] = 1366.07;
                HouseInfo[houseid][InPosZ] = 1083.65;
                HouseInfo[houseid][Interior] = 5;
                HouseInfo[houseid][Price] = 3000; // abaixo de 10000 vai ser DP
            }
        }
        HouseInfo[houseid][Owner] = 0;
        HouseInfo[houseid][FHQ] = 0;
        HouseInfo[houseid][ID] = houseid;
        GetPlayerPos(playerid, HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ]);
       

       
        format(query, sizeof(query), "INSERT INTO houses SET ID = %d, InPosX = %f, InPosY = %f, InPosZ = %f, OutPosX = %f, OutPosY = %f, OutPosZ = %f, World = %d, Price = %d, Owner = %d, Dono = '%s', Money = %d, Maconha = %d, FHQ = %d, Interior = %d",
            HouseInfo[houseid][ID], HouseInfo[houseid][InPosX], HouseInfo[houseid][InPosY], HouseInfo[houseid][InPosZ], HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ], HouseInfo[houseid][World], HouseInfo[houseid][Price], HouseInfo[houseid][Owner], HouseInfo[houseid][Locked], HouseInfo[houseid][Dono], HouseInfo[houseid][Money], HouseInfo[houseid][Maconha], HouseInfo[houseid][FHQ], HouseInfo[houseid][Interior] );
       
        format(string, sizeof(string), "%s criou uma nova casa!", PlayerName(playerid) );
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        RefreshHouses();
        return 1;
    }
Nem quando o servidor reinicia depois de ter criado
Ongamemodeexit: SalvarCasas();
pawn Код:
stock SalvarCasas() {  
    for(new houseid; houseid < MAX_HOUSES; houseid++)
    {
        new query[1024];
        format(query, sizeof(query), "UPDATE houses SET OutPosX = %f , OutPosY = %f, OutPosZ = %f, InPosX = %f, InPosY = %f, InPosZ = %f, ",
            HouseInfo[houseid][ID], HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ], HouseInfo[houseid][InPosX], HouseInfo[houseid][InPosY], HouseInfo[houseid][InPosZ]);
        format(query, sizeof(query), "%s World = %d, Price = %d, Interior = %d, Locked = %d, Dono = %s, FHQ = %d, Money = %d, Maconha = %d, Owner = %d WHERE ID = %d",
            query, HouseInfo[houseid][World], HouseInfo[houseid][Price], HouseInfo[houseid][Interior], HouseInfo[houseid][Locked], HouseInfo[houseid][Dono], HouseInfo[houseid][FHQ], HouseInfo[houseid][Money], HouseInfo[houseid][Maconha], HouseInfo[houseid][Owner], HouseInfo[houseid][ID]);
        mysql_pquery(ConnectMYSQL, query);
    }
}
Reply
#2

Sйrio, busca no ****** como se usar SQL. isso aqui tб super errado
pawn Код:
"INSERT INTO houses SET ID = %d, InPosX = %f, InPosY = %f, InPosZ = %f, OutPosX = %f, OutPosY = %f, OutPosZ = %f, World = %d, Price = %d, Owner = %d, Dono = '%s', Money = %d, Maconha = %d, FHQ = %d, Interior = %d"
Reply
#3

http://www.w3schools.com/sql/sql_insert.asp

Ajudara voce bastante a entender.
Reply
#4

pawn Код:
INSERT INTO `tabela` ( `coluna` ) VALUES ('resposta')
Reply
#5

Nгo estб certo assim?
pawn Код:
CMD:makehouse(playerid, params[]) {
        if(admin[playerid] < 6) return 0;
        new houseid, type;
        new query[1024];
        new string[80];
        if(sscanf(params,"ii", houseid, type)) {
            SendClientMessage(playerid, -1, "Use: /makehouse [houseid] [type]");
            SendClientMessage(playerid, -1, "types: 1-pequena 2-media 3-grande 4-mansгo 5-vip");
            return 1;
        }
        switch( type ) {
            case 1: { // Pequena
                HouseInfo[houseid][InPosX] = 223.20;
                HouseInfo[houseid][InPosY] = 1287.08;
                HouseInfo[houseid][InPosZ] = 1082.14;
                HouseInfo[houseid][Interior] = 1;
                HouseInfo[houseid][Price] = 500000;
            }
            case 2: { // media
                HouseInfo[houseid][InPosX] = 2365.31;
                HouseInfo[houseid][InPosY] = -1135.60;
                HouseInfo[houseid][InPosZ] = 1050.88;
                HouseInfo[houseid][Interior] = 8;
                HouseInfo[houseid][Price] = 3000000;
            }
            case 3: { // grande
                HouseInfo[houseid][InPosX] = 446.99;
                HouseInfo[houseid][InPosY] = 1397.07;
                HouseInfo[houseid][InPosZ] = 1084.30;
                HouseInfo[houseid][Interior] = 2;
                HouseInfo[houseid][Price] = 10000000;
            }
            case 4: { // mansгo
                HouseInfo[houseid][InPosX] = 2196.85;
                HouseInfo[houseid][InPosY] = -1204.25;
                HouseInfo[houseid][InPosZ] = 1049.02;
                HouseInfo[houseid][Interior] = 6;
                HouseInfo[houseid][Price] = 100000000;

            }
            case 5: { // VIP
                HouseInfo[houseid][InPosX] = 140.17;
                HouseInfo[houseid][InPosY] = 1366.07;
                HouseInfo[houseid][InPosZ] = 1083.65;
                HouseInfo[houseid][Interior] = 5;
                HouseInfo[houseid][Price] = 3000; // abaixo de 10000 vai ser DP
            }
        }
        HouseInfo[houseid][Owner] = 0;
        HouseInfo[houseid][FHQ] = 0;
        HouseInfo[houseid][ID] = houseid;
        GetPlayerPos(playerid, HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ]);
       
        format(query, sizeof(query), "INSERT INTO `houses` SET `OutPosX` = '%f' , `OutPosY` = '%f', `OutPosZ` = '%f', `InPosX` = '%f', `InPosY` = '%f', `InPosZ` = '%f', ",
            HouseInfo[houseid][ID], HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ], HouseInfo[houseid][InPosX], HouseInfo[houseid][InPosY], HouseInfo[houseid][InPosZ]);
        format(query, sizeof(query), "%s `World` = '%d', `Price` = '%d', `Interior` = '%d', `Locked` = '%d', `Dono` = '%s', `FHQ` = '%d', `Money` = '%d', `Maconha` = '%d', `Owner` = '%d' WHERE `ID` = '%d'",
            query, HouseInfo[houseid][World], HouseInfo[houseid][Price], HouseInfo[houseid][Interior], HouseInfo[houseid][Locked], HouseInfo[houseid][Dono], HouseInfo[houseid][FHQ], HouseInfo[houseid][Money], HouseInfo[houseid][Maconha], HouseInfo[houseid][Owner], HouseInfo[houseid][ID]);
        mysql_pquery(ConnectMYSQL, query);
       
        format(string, sizeof(string), "%s criou uma nova casa!", PlayerName(playerid) );
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        RefreshHouses();
        return 1;
    }
Pq nгo estб registrando?
Qnd troca a linha tem q colocar um %s? Pq?
Reply
#6

Tenta trocar
Код:
mysql_pquery(ConnectMYSQL, query);
Por
Код:
mysql_query(ConnectMYSQL, query);
Mande o seu
Код:
mysql_log.txt
mas certamente vocк deve estar errando no format
Reply
#7

To tentando assim:
pawn Код:
CMD:makehouse(playerid, params[]) {
        if(admin[playerid] < 6) return 0;
        new houseid, type;
        new query[1024];
        new string[80];
        if(sscanf(params,"ii", houseid, type)) {
            SendClientMessage(playerid, -1, "Use: /makehouse [houseid] [type]");
            SendClientMessage(playerid, -1, "types: 1-pequena 2-media 3-grande 4-mansгo 5-vip");
            return 1;
        }
        switch( type ) {
            case 1: { // Pequena
                HouseInfo[houseid][InPosX] = 223.20;
                HouseInfo[houseid][InPosY] = 1287.08;
                HouseInfo[houseid][InPosZ] = 1082.14;
                HouseInfo[houseid][Interior] = 1;
                HouseInfo[houseid][Price] = 500000;
            }
            case 2: { // media
                HouseInfo[houseid][InPosX] = 2365.31;
                HouseInfo[houseid][InPosY] = -1135.60;
                HouseInfo[houseid][InPosZ] = 1050.88;
                HouseInfo[houseid][Interior] = 8;
                HouseInfo[houseid][Price] = 3000000;
            }
            case 3: { // grande
                HouseInfo[houseid][InPosX] = 446.99;
                HouseInfo[houseid][InPosY] = 1397.07;
                HouseInfo[houseid][InPosZ] = 1084.30;
                HouseInfo[houseid][Interior] = 2;
                HouseInfo[houseid][Price] = 10000000;
            }
            case 4: { // mansгo
                HouseInfo[houseid][InPosX] = 2196.85;
                HouseInfo[houseid][InPosY] = -1204.25;
                HouseInfo[houseid][InPosZ] = 1049.02;
                HouseInfo[houseid][Interior] = 6;
                HouseInfo[houseid][Price] = 100000000;

            }
            case 5: { // VIP
                HouseInfo[houseid][InPosX] = 140.17;
                HouseInfo[houseid][InPosY] = 1366.07;
                HouseInfo[houseid][InPosZ] = 1083.65;
                HouseInfo[houseid][Interior] = 5;
                HouseInfo[houseid][Price] = 3000; // abaixo de 10000 vai ser DP
            }
        }
        HouseInfo[houseid][Owner] = 0;
        HouseInfo[houseid][FHQ] = 0;
        HouseInfo[houseid][ID] = houseid;
        GetPlayerPos(playerid, HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ]);
       
        format(query, sizeof(query), "INSERT INTO `houses` SET `OutPosX` = '%f' , `OutPosY` = '%f', `OutPosZ` = '%f', `InPosX` = '%f', `InPosY` = '%f', `InPosZ` = '%f', ",
            HouseInfo[houseid][ID], HouseInfo[houseid][OutPosX], HouseInfo[houseid][OutPosY], HouseInfo[houseid][OutPosZ], HouseInfo[houseid][InPosX], HouseInfo[houseid][InPosY], HouseInfo[houseid][InPosZ]);
        format(query, sizeof(query), "%s `World` = '%d', `Price` = '%d', `Interior` = '%d', `Locked` = '%d', `Dono` = '%s', `FHQ` = '%d', `Money` = '%d', `Maconha` = '%d', `Owner` = '%d' WHERE `ID` = '%d'",
            query, HouseInfo[houseid][World], HouseInfo[houseid][Price], HouseInfo[houseid][Interior], HouseInfo[houseid][Locked], HouseInfo[houseid][Dono], HouseInfo[houseid][FHQ], HouseInfo[houseid][Money], HouseInfo[houseid][Maconha], HouseInfo[houseid][Owner], HouseInfo[houseid][ID]);
        mysql_pquery(ConnectMYSQL, query);
       
        format(string, sizeof(string), "%s criou uma nova casa!", PlayerName(playerid) );
        SendClientMessage(playerid, COLOR_LIGHTRED, string);
        RefreshHouses();
        return 1;
    }
Onde estб o erro de sintaxe?
%d precisa de ''?
qnd pula uma linha tem q botar %s? pq?


[12:15:47] [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 'WHERE `ID` = '1'' at line 1
Reply
#8

??
Reply
#9

Criou a tabela certinho ? pelo visto parece que nгo ..
Reply
#10

Filho, mau.tito, PT e Skream jб disseram o que vocк errou e onde errou.

Para usar insert vocк deve seguir este padrгo (como o mau.tito falou):
Код:
INSERT INTO `tabela` ( `coluna` ) VALUES ('resposta')
OU SEJA:
Код:
"INSERT INTO TABELA = houses (COLUNAS = OutPosX, OutPosY... ) VALUES (RESPOSTAS = '%f', '%f' ...)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)