MySQL returning different values
#1

Every time a new player registers, they get assigned random integers as their stats.
For example, my starting cash is $48 (default is 10000, I even insert 10000 in upon registration just to make sure) and their admin level is always 1120403456. I can't change it; whenever they go in-game it reverts back to this.

I used
pawn Код:
mysql_fetch_field("AdminLevel", val); PlayerInfo[playerid][pAdmin] = strval(val);
to get the admin level in the database and assign its numerical value to 'pAdmin' (the admin level is default 0 too)
Even if I delete the field entirely and leave it as null, it reverts to its weird number.

I wanted to find out why I was getting that, so did this:
pawn Код:
mysql_fetch_field("AdminLevel", val);
printf("%s %d %f", val, val, val);
mysql_fetch_field("AdminLevel", val); PlayerInfo[playerid][pAdmin] = strval(val);
printf("%d", PlayerInfo[playerid][pAdmin]);
My result was this:
[22:49:17] y_Tucker 1 0.000000
[22:49:17] 0

Am I doing something wrong with the MySQL code, or is it something else? I don't understand why I'm getting different values each time I do it (hence 1 on the first test and 0 on the second).

I also have a problem with the password field:
pawn Код:
format(index,128,"SELECT * FROM Users WHERE Username = '%s'", PlayerName(playerid));
            mysql_query(index);
            mysql_store_result();
            mysql_fetch_field("Password", pwresult);
            printf("%s", pwresult);
            printf("%s", password);
            printf("%d", strcmp(password, pwresult, true));
I can log in and it says 'correct password', and if it's not the correct password it says 'incorrect password'. Strangely, however, it also says this:
[MySQL] Error (0): Function: mysql_fetch_field failed, no field data.
Printing 'pwresult' yields blank space while 'password' yields my typed password. However, when comparing the two 'pwresult' seems to exist and function correctly.

I've tried all three of these methods:
pawn Код:
format(string,512,"INSERT INTO `Users` (Username) VALUES ('%s')",PlayerName(playerid));
        mysql_query(string);
       
        format(string,512,"UPDATE Users SET Password = '%s' WHERE Username = '%s'",password, PlayerName(playerid));
        mysql_query(string);
pawn Код:
format(string,512,"INSERT INTO `Users` (Username, Password) VALUES ('%s','%s')",PlayerName(playerid),PlayerInfo[playerid][pPassword]);
        mysql_query(string);
pawn Код:
format(string,512,"INSERT INTO `Users` (Username, Password, AdminLevel, Cash) VALUES ('%s','%s',0,10000)",PlayerName(playerid),PlayerInfo[playerid][pPassword]);
        mysql_query(string);
All three give me the correct username and password, however the numbers in the database are different (not random; they're the same each time). I tried putting the numbers in inverted commas and got the same result.

I've used both varchar and int types in my CREATE TABLE query, and both times they have completely different results to what my input is.

I use StrickenKid's MySQL 2.1.1 on Linux.
Reply
#2

Quote:

I use StrickenKid's MySQL 2.1.1 on Linux.

Solved.

StrickenKid's MySQL Plugin is really outdated, you should use Dan's or BlueG's.
Reply
#3

Alright, I'll convert now. Thanks!
Reply
#4

I'm still getting the wrong data (the same data as before). It worked perfectly with ini files, but won't with MySQL. Using Dan's plugin; it assigns the same number to AdminLevel even if I declare the variable as 0 on the line above.

My MySQL query is AdminLevel int default 0, however when I insert just the username and password (so it should automatically assign the default values) it changes half of them, and the same ones each time. If I run the same query on an SQL client, I get the correct values. If anyone could offer any insight onto this I'd be grateful.
Reply
#5

Nevermind, found the problem.
I had Float: pHealth = 100, in my pInfo enum.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)