SQL issue.
#1

I'm having a small problem with a query, not actually inserting the data into the database.


pawn Код:
format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET `Mod1`=%d, `Mod2`=%d, `Mod3`=%d, `Mod4`=%d, `Mod5`=%d, `Mod6`=%d, `Mod7`=%d, `Mod8`=%d, `Mod9`=%d, `Mod10`=%d,\
    `Mod11` = %d, `Mod12`=%d, `Mod13`=%d, `Mod14`=%d, `Mod15`=%d, `Mod16`=%d, `Mod17` WHERE `OwnedVehicleID` = %i LIMIT 1"
,
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10],
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);

    mysql_query(Query);
That there, doesn't insert the above items into the actual table.
Reply
#2

This is UPDATE, not INSERT. it updates already inserted data.

pawn Код:
INSERT INTO table_name ( field1, field2,...fieldN ) VALUES( value1, value2,...valueN )
and
pawn Код:
UPDATE table_name SET column1=value, column2=value2 WHERE some_column=some_value
Reply
#3

I meant updating.. It's not updating the data correctly.
Reply
#4

Make sure the table is called PlayerVehicles.
pawn Код:
format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET Mod1=%d, Mod2=%d, Mod3=%d, Mod4=%d, Mod5=%d, Mod6=%d, Mod7=%d, Mod8=%d, Mod9=%d, Mod10=%d, \
    Mod11=%d, Mod12=%d, Mod13=%d, Mod14=%d, Mod15=%d, Mod16=%d, Mod17=%d WHERE OwnedVehicleID=%d"
,
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10],
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);

    print(Query); // Debug
    mysql_query(Query);
Show what it prints and if it still does not update, there's a way.
For example on SQLite, I can execute SQL from a database editor, if there is error, it says which one.
Reply
#5

Yo Getty! There was one missing integer specifier in your code.

pawn Код:
format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET `Mod1`='%d', `Mod2`='%d', `Mod3`='%d', `Mod4`='%d', `Mod5`='%d', `Mod6`='%d', `Mod7`='%d', `Mod8`='%d', `Mod9`='%d', `Mod10`='%d',\
    `Mod11` = '%d', `Mod12`='%d', `Mod13`='%d', `Mod14`='%d', `Mod15`='%d', `Mod16`='%d', `Mod17`= '%d' WHERE `OwnedVehicleID` = %i LIMIT 1"
,
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10],
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);
   
    mysql_query(Query);
Or you can also do with strcat.

pawn Код:
new Query2[200]
    format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET `Mod1`='%d', `Mod2`='%d', `Mod3`='%d', `Mod4`='%d', `Mod5`='%d', `Mod6`='%d', `Mod7`='%d', `Mod8`='%d', `Mod9`='%d', `Mod10`='%d'",
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10]);
    format(Query2,sizeof(Query2),"`Mod11` = '%d', `Mod12`='%d', `Mod13`='%d', `Mod14`='%d', `Mod15`='%d', `Mod16`='%d', `Mod17`= '%d' WHERE `OwnedVehicleID` = %d LIMIT 1",
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);
    strcat(Query,Query2);
   
    mysql_query(Query);
Reply
#6

Код:
[52:12 - 05] UPDATE `PlayerVehicles` SET Mod1=0, Mod2=0, Mod3=0, Mod4=0, Mod5=0, Mod6=0, Mod7=0, Mod8=0, Mod9=0, Mod10=0, Mod12=0, Mod13=0, Mod13=0, Mod14=0, Mod15=0, Mod16=0, Mod17=0 WHERE OwnedVehicleID=2
[52:12 - 05] Vehicle ID: 56 - Component ID: 1014
Reply
#7

Код:
[52:12 - 05] UPDATE [..] Mod8=0, Mod9=0, Mod10=0, Mod12=0, Mod13=0, Mod13=0, Mod14=0, Mod15=0, Mod16=0, Mod17=0 WHERE OwnedVehicleID=2
it's mod10,12,13,13. You're missing 11 as Ballu Miaa said it above.

pawn Код:
format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET Mod1=%d, Mod2=%d, Mod3=%d, Mod4=%d, Mod5=%d, Mod6=%d, Mod7=%d, Mod8=%d, Mod9=%d, Mod10=%d, \
    Mod11=%d, Mod12=%d, Mod13=%d, Mod14=%d, Mod15=%d, Mod16=%d, Mod17=%d WHERE OwnedVehicleID=%d"
,
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10],
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);

    mysql_query(Query);
Reply
#8

Thank you both!
Reply
#9

The mods still aren't saving..


pawn Код:
format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET `Mod1`=%d, `Mod2`=%d, `Mod3`=%d, `Mod4`=%d, `Mod5`=%d, `Mod6`=%d, `Mod7`=%d, `Mod8`=%d, `Mod9`=%d, `Mod10`=%d WHERE `OwnedVehicleID` = %d LIMIT 1",
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10],
    iVehicleID);
   
    mysql_query(Query);
   
    format(Query,sizeof(Query),"UPDATE `PlayerVehicles` SET `Mod11` = '%d', `Mod12`='%d', `Mod13`='%d', `Mod14`='%d', `Mod15`='%d', `Mod16`='%d', `Mod17`= '%d' WHERE `OwnedVehicleID` = %d LIMIT 1",
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);

    mysql_query(Query);
Reply
#10

Getty use this code! This will work fine for you!! We gotta format two strings and strcat these two strings together.

pawn Код:
new Query2[200]
    format(Query, sizeof(Query), "UPDATE `PlayerVehicles` SET `Mod1`='%d', `Mod2`='%d', `Mod3`='%d', `Mod4`='%d', `Mod5`='%d', `Mod6`='%d', `Mod7`='%d', `Mod8`='%d', `Mod9`='%d', `Mod10`='%d'",
    Vehicles[iVehicleID][mod1],
    Vehicles[iVehicleID][mod2],
    Vehicles[iVehicleID][mod3],
    Vehicles[iVehicleID][mod4],
    Vehicles[iVehicleID][mod5],
    Vehicles[iVehicleID][mod6],
    Vehicles[iVehicleID][mod7],
    Vehicles[iVehicleID][mod8],
    Vehicles[iVehicleID][mod9],
    Vehicles[iVehicleID][mod10]);
    format(Query2,sizeof(Query2),"`Mod11` = '%d', `Mod12`='%d', `Mod13`='%d', `Mod14`='%d', `Mod15`='%d', `Mod16`='%d', `Mod17`= '%d' WHERE `OwnedVehicleID` = %d LIMIT 1",
    Vehicles[iVehicleID][mod11],
    Vehicles[iVehicleID][mod12],
    Vehicles[iVehicleID][mod13],
    Vehicles[iVehicleID][mod14],
    Vehicles[iVehicleID][mod15],
    Vehicles[iVehicleID][mod16],
    Vehicles[iVehicleID][mod17],
    iVehicleID);
    strcat(Query,Query2);
   
    mysql_query(Query);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)