SQLite not writing to database
#1

I decided to learn SQL, and changed my login system from YINI to SQLite. When you register an account, it does not write your info to the database, and therefore, you cannot log in. Whats the issue?

pawn Код:
if(dialogid == DIALOG_REGISTER)
        {
        if (!response) return Kick(playerid);
        if(response)
            {
            format(Query, sizeof(Query), "INSERT INTO `ACCOUNTS` (`NAME`, `PASSWORD`, `IP`, `LEVEL`, `CASH`, `ADMINLEVEL`, `HOURS`, `JOB`, `BANNED`, `SPAWN`, `BANK`, `FOOD`, `WATER`, `SKIN`, `FACTION`, `FACTION LEVEL`) VALUES('%s','%s','%s', '1', '2000', '0', '0', '0', '0', '0', '0', '432000', '432000', '2', '0', '0')", DB_Escape(name), DB_Escape(inputtext), DB_Escape(ip));
            db_query(survival, Query);
            GivePlayerMoney(playerid, 2000);
            SetSpawnInfo(playerid, 0, 1, 1242.0341,327.7363,19.7555, 0, 0, 0, 0, 0, 0, 0 );
            SpawnPlayer(playerid);
            //ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Enter your password below:", "Login", "Cancel");
            return 1;
            }
        }
The database is blank after registering.
Reply
#2

numbers not in ' ' but ` ` or without, just 1, 2000
Reply
#3

Is the Query big enough?
Is every field's name written correctly?

The disadvantage SQLite has is that you don't know if an error occurs while executing a query. The only way to figure it out is doing:

pawn Код:
format(Query, sizeof(Query), "INSERT INTO `ACCOUNTS` (`NAME`, `PASSWORD`, `IP`, `LEVEL`, `CASH`, `ADMINLEVEL`, `HOURS`, `JOB`, `BANNED`, `SPAWN`, `BANK`, `FOOD`, `WATER`, `SKIN`, `FACTION`, `FACTION LEVEL`) VALUES('%s','%s','%s', '1', '2000', '0', '0', '0', '0', '0', '0', '432000', '432000', '2', '0', '0')", DB_Escape(name), DB_Escape(inputtext), DB_Escape(ip));
db_query(survival, Query);
print(Query);
So if the message is not the whole, make the size bigger. If the lenght is fine then use SQLite Database Browser and open your database. Go and execute the query was printed before (if its lenght is fine) and if there are any errors in the fields or something like that, it will write it down.
Reply
#4

The string size for the query was 250 for the login and register system, I made it 500, all is good now! THanks!
Reply
#5

I take that back..its still not saving, though it loads the info now.

OnPlayerDisconnect:
pawn Код:
public OnPlayerDisconnect(playerid)
    {
    new
        Query[ 200 ],
        name[ MAX_PLAYER_NAME ]
    ;
    GetPlayerName(playerid, name, sizeof(name));
    format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET LEVEL = '%d', CASH = '%d', ADMINLEVEL = '%d', HOURS = '%d', JOB = '%d', BANNED = '%d', SPAWN = '%d', BANK = '%d', FOOD = '%d', WATER = '%d', SKIN = '%d', FACTION = '%d', FACTION LEVEL = '%d' COLLATE NOCASE", PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pCash], PlayerInfo[playerid][pAdmin],
    PlayerInfo[playerid][pHours], PlayerInfo[playerid][pJob], PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pSpawn], PlayerInfo[playerid][pBank], PlayerInfo[playerid][pFood], PlayerInfo[playerid][pWater], PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pFaction], PlayerInfo[playerid][pFlevel]);
    db_query(survival, Query);
    return 1;
    }
Reply
#6

pawn Код:
format(Query, sizeof(Query), "UPDATE `ACCOUNTS` SET LEVEL = %d, CASH = %d, ADMINLEVEL = %d, HOURS = %d, JOB = %d, BANNED = %d, SPAWN = %d, BANK = %d, FOOD = %d, WATER = %d, SKIN = %d, FACTION = %d, FACTION LEVEL = %d WHERE NAME = '%s'",
+ add name to the end of format
Reply
#7

Extended the query on OnPlayerDisconnect, all is good now!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)