MySql not saving
#1

I had this problem before, sqlite doesnt write to the database. I had fixed the issue and it WAS working, but now it is not working again, it simply does not write info to the table.

pawn Код:
new//under OnPlayerConnect
        Query[ 150 ],
        DBResult: Result,
        name[ MAX_PLAYER_NAME ]
    ;
    GetPlayerName(playerid, name, sizeof(name));
    format(Query, sizeof(Query), "SELECT `NAME` FROM `ACCOUNTS` WHERE `NAME` = '%s' COLLATE NOCASE", DB_Escape(name));
    Result = db_query(survival, Query);
   
    if(db_num_rows(Result))
        {
        new loginstring[100];
        format(loginstring, sizeof(loginstring), "Welcome back!\n{00FF00}Username: {FFFFFF}%s\nEnter your password below\nto get playing!", name);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", loginstring, "Login", "Cancel");
        }
    else
        {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,"Register","Your account is not registered.\nPlease create a password and click register!","Register","Quit");
        }
    db_free_result(Result);
    }

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
    {
    new
        Query[ 800 ],
        DBResult: Result,
        name[ MAX_PLAYER_NAME ],
        ip[ 16 ];
       
    GetPlayerName(playerid, name, sizeof(name));
    GetPlayerIp(playerid, ip, sizeof(ip));
    //Login System
    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);
            ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, "Login", "Enter your password below:", "Login", "Cancel");
            return 1;
            }
        }
    if(dialogid == DIALOG_LOGIN)
        {
        if(!response) return Kick(playerid);
        if(response)
            {
            format(Query, sizeof(Query), "SELECT * FROM `ACCOUNTS` WHERE `NAME` = '%s' COLLATE NOCASE AND `PASSWORD` = '%s'", DB_Escape(name), DB_Escape(inputtext));
            Result = db_query(survival, Query);
            if(db_num_rows(Result))
                {
                new Field[ 20 ];
                db_get_field_assoc(Result, "LEVEL", Field, 30);
                PlayerInfo[playerid][pLevel] = strval(Field);
                db_get_field_assoc(Result, "CASH", Field, 30);
                GivePlayerMoney(playerid, strval(Field));
                db_get_field_assoc(Result, "ADMINLEVEL", Field, 30);
                PlayerInfo[playerid][pAdmin] = strval(Field);
                db_get_field_assoc(Result, "HOURS", Field, 30);
                PlayerInfo[playerid][pHours] = strval(Field);
                db_get_field_assoc(Result, "JOB", Field, 30);
                PlayerInfo[playerid][pJob] = strval(Field);
                db_get_field_assoc(Result, "BANNED", Field, 30);
                PlayerInfo[playerid][pBanned] = strval(Field);
                db_get_field_assoc(Result, "SPAWN", Field, 30);
                PlayerInfo[playerid][pSpawn] = strval(Field);
                db_get_field_assoc(Result, "BANK", Field, 30);
                PlayerInfo[playerid][pBank] = strval(Field);
                db_get_field_assoc(Result, "FOOD", Field, 30);
                PlayerInfo[playerid][pWater] = strval(Field);
                db_get_field_assoc(Result, "SKIN", Field, 30);
                PlayerInfo[playerid][pSkin] = strval(Field);
                db_get_field_assoc(Result, "FACTION", Field, 30);
                PlayerInfo[playerid][pFaction] = strval(Field);
                db_get_field_assoc(Result, "FACTION LEVEL", Field, 30);
                PlayerInfo[playerid][pFlevel] = strval(Field);
                db_get_field_assoc(Result, "HOURS", Field, 30);
                PlayerInfo[playerid][pHours] = strval(Field);
                SetSpawnInfo(playerid, 0, 1, 1242.0341,327.7363,19.7555, 0, 0, 0, 0, 0, 0, 0 );
                SpawnPlayer(playerid);
                return 1;
                }
            else
                {
                ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD,"Login","{FF0000}Error:{FFFFFF} You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
            }
        }
pawn Код:
public OnPlayerDisconnect(playerid)
    {
    new
        Query[500],
        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' WHERE NAME = '%s'", 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], GetName(playerid));
    db_query(survival, Query);
    return 1;
    }
Reply
#2

Are you trying to update a mysql database with sqlite? SQLite creates a .db file in scriptfiles directory where all the information is saved.
Reply
#3

Quote:
Originally Posted by zPain
Посмотреть сообщение
Are you trying to update a mysql database with sqlite? SQLite creates a .db file in scriptfiles directory where all the information is saved.
No everything is SQLite, idk why I wrote mysql in the title :P
Reply
#4

Are you sure that all fields have been created and the types were specified correctly?
Reply
#5

Quote:
Originally Posted by zPain
Посмотреть сообщение
Are you sure that all fields have been created and the types were specified correctly?
I'm almost positive, cause it was working...And I just realized, the reason it wouldnt register was my login system. When you register, it writes the default data, but it does not update, for example your skin and admin level as well as money.
Reply
#6

Let me see the table creation code.
Reply
#7

pawn Код:
db_query(survival, "CREATE TABLE IF NOT EXISTS `ACCOUNTS` (`NAME`, `PASSWORD`, `IP`, `LEVEL`, `CASH`, `ADMINLEVEL`, `HOURS`, `JOB`, `BANNED`, `SPAWN`, `BANK`, `FOOD`, `WATER`, `SKIN`, `FACTION`, `FACTION LEVEL`)");
Reply
#8

Specify the field type. Maybe it solves the problem.
Reply
#9

How do you mean? Im a noob, just started sqlite the other day
Reply
#10

yay,
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)