MySQL - Query not storing data
#1

Any reason that this Query isn't submitting?

pawn Код:
// Should store the ID, the VehicleID and if the car is Linked
                    format(query,sizeof(query), "INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES('%d','%d','%s','%d')",i,car,playerid);
                    mysql_query(query);
Should store the ID, the VehicleID and if the car is Linked

In the table 'VehicleKeys' there are 3 rows
-ID
-VehicleID
-Linked

The query Right above it that stores the vehicles in the 'Vehicle' table stores fine.
Reply
#2

You specified too many values:

pawn Код:
"INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES('%d','%d','%s','%d')"
You're only specifying 3 columns to insert a value into, yet you specify 4 values?

It should be more along the lines of this:

pawn Код:
"INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES(%d,%d,%d)"
Reply
#3

Use mysql_debug(1); at OnGameModeInit and check if you are connected and whether the query was succesfull. A new file should be created.
Reply
#4

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You specified too many values:

pawn Код:
"INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES('%d','%d','%s','%d')"
You're only specifying 3 columns to insert a value into, yet you specify 4 values?

It should be more along the lines of this:

pawn Код:
"INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES(%d,%d,%d)"
Yea I fixed that soon after I posted and it is still not storing data.

Quote:
Originally Posted by Strawhats
Посмотреть сообщение
Use mysql_debug(1); at OnGameModeInit and check if you are connected and whether the query was succesfull. A new file should be created.
Yea, I already have that and nothing out of the ordinary is showing up in my mysql_log

Код:
[Mon Jun 25 23:48:24 2012] -------------------------
[Mon Jun 25 23:48:24 2012]      Logging Started
[Mon Jun 25 23:48:24 2012] -------------------------
[Tue Jun 26 00:01:59 2012] -------------------------
[Tue Jun 26 00:01:59 2012]       Logging Ended
[Tue Jun 26 00:01:59 2012] -------------------------
[00:32:13] Unloading Plugin
[00:32:25] Unloading Plugin
[Tue Jun 26 00:42:30 2012] -------------------------
[Tue Jun 26 00:42:30 2012]      Logging Started
[Tue Jun 26 00:42:30 2012] -------------------------
[Tue Jun 26 00:43:21 2012] -------------------------
[Tue Jun 26 00:43:21 2012]      Logging Started
[Tue Jun 26 00:43:21 2012] -------------------------
[Tue Jun 26 00:44:26 2012] -------------------------
[Tue Jun 26 00:44:26 2012]       Logging Ended
[Tue Jun 26 00:44:26 2012] -------------------------
[Tue Jun 26 00:44:28 2012] -------------------------
[Tue Jun 26 00:44:28 2012]      Logging Started
[Tue Jun 26 00:44:28 2012] -------------------------
[Tue Jun 26 16:20:19 2012] -------------------------
[Tue Jun 26 16:20:19 2012]      Logging Started
[Tue Jun 26 16:20:19 2012] -------------------------
[Tue Jun 26 16:21:25 2012] -------------------------
[Tue Jun 26 16:21:25 2012]      Logging Started
[Tue Jun 26 16:21:25 2012] -------------------------
[Tue Jun 26 16:21:51 2012] -------------------------
[Tue Jun 26 16:21:51 2012]       Logging Ended
[Tue Jun 26 16:21:51 2012] -------------------------
[Tue Jun 26 16:21:55 2012] -------------------------
[Tue Jun 26 16:21:55 2012]      Logging Started
[Tue Jun 26 16:21:55 2012] -------------------------
[Tue Jun 26 16:22:42 2012] -------------------------
[Tue Jun 26 16:22:42 2012]      Logging Started
[Tue Jun 26 16:22:42 2012] -------------------------
[Tue Jun 26 16:37:05 2012] -------------------------
[Tue Jun 26 16:37:05 2012]       Logging Ended
[Tue Jun 26 16:37:05 2012] -------------------------
[Tue Jun 26 16:37:07 2012] -------------------------
[Tue Jun 26 16:37:07 2012]       Logging Ended
[Tue Jun 26 16:37:07 2012] -------------------------
[Tue Jun 26 16:40:00 2012] -------------------------
[Tue Jun 26 16:40:00 2012]      Logging Started
[Tue Jun 26 16:40:00 2012] -------------------------
[Tue Jun 26 16:43:02 2012] -------------------------
[Tue Jun 26 16:43:02 2012]       Logging Ended
[Tue Jun 26 16:43:02 2012] -------------------------
[16:51:30] Unloading Plugin
[19:10:34] Unloading Plugin
Reply
#5

This is a common mistake people make with mysql,

Код:
format(query,sizeof(query), "INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES('%d','%d','%s','%d')",i,car,playerid);
That is incorrect, it should be this:

Код:
format(query,sizeof(query), "INSERT INTO `VehicleKeys` (ID,VehicleID,Linked) VALUES('%d','%d','%s','%d');",i,car,playerid);
Notice, you forgot the ";" after you close the values bracket.. it makes all the difference..
Reply
#6

Eh, Not sure on that but 'JaTochNietDan' was right, I noticed what I though I fixed was different from what I did fix.

So all I did was remove the '%s' and it worked a charm except now I am trying to create a 'AccountID' for login and

pawn Код:
new i = GetNextSQL("AccountID", "Accounts");
Player[playerid][pAccountID] = i;
Doesn't seem to be working.
Reply
#7

Just use "Auto_Increment" on the SQL table.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)