mysql problem
#1

how come when some body connects to server, sometimes they will get random score and everything like 9546464
pawn Code:
public Save(playerid)
{
    if(Logged[playerid] == 1)
    {
        if(!IsPlayerNPC(playerid) && spawned[playerid] == 1)
        {
        CheckMySQL();
        PlayerData[playerid][Interior] = GetPlayerInterior(playerid);
        GetPlayerPos(playerid,X,Y,Z);
        GetPlayerName(playerid,pname,sizeof(pname));
        format(query,sizeof(query),"UPDATE accounts SET AdminLevel = %d,Cash = %d,vip = %d,Member = %d,Leader = %d,IsInOrg = %d,IsLaw = %d,IsGang = %d,IsPriv = %d,WantedLevel = %d,MinutesPlayed = %d,HoursPlayed = %d,Level = %d,Cig = %d,Sprunk = %d,Snack = %d,Lighter = %d WHERE Name = '%s'",
        PlayerData[playerid][AdminLevel],GetPlayerMoney(playerid),PlayerData[playerid][vip],PlayerData[playerid][Member],PlayerData[playerid][Leader],PlayerData[playerid][IsInOrg],PlayerData[playerid][IsLaw],PlayerData[playerid][IsGang],PlayerData[playerid][IsPriv],GetPlayerWantedLevel(playerid),PlayerData[playerid][MinutesPlayed],PlayerData[playerid][HoursPlayed],GetPlayerScore(playerid),PlayerData[playerid][Cig],PlayerData[playerid][Sprunk],PlayerData[playerid][Snack],PlayerData[playerid][Lighter],pname);
        mysql_query(query);
        format(query,sizeof(query),"UPDATE accounts SET FightingStyle = %d,Passport = %d,Bag = %d,GunLicense = %d,Job = %d,Pot = %d,Crack = %d,Bank = %d,BankAccount = %d,CarLicense = %d,Fuelcan = %d,Civilskin = %d,MinutesToNextLevel = %d,simcard = %d,phone = %d,phonebook = %d WHERE Name = '%s'",
        PlayerData[playerid][FightingStyle],PlayerData[playerid][Passport],PlayerData[playerid][Bag],PlayerData[playerid][GunLicense],PlayerData[playerid][Job],PlayerData[playerid][Pot],PlayerData[playerid][Crack],PlayerData[playerid][Bank],PlayerData[playerid][BankAccount],PlayerData[playerid][CarLicense],PlayerData[playerid][Fuelcan],PlayerData[playerid][Civilskin],PlayerData[playerid][MinutesToNextLevel],PlayerData[playerid][simcard],PlayerData[playerid][phone],PlayerData[playerid][phonebook],pname);
        mysql_query(query);
        format(query,sizeof(query),"UPDATE accounts SET X = %f,Y = %f,Z = %f,Interior = %d,BoatLicense = %d WHERE Name = '%s'",
        X,Y,Z,PlayerData[playerid][Interior],PlayerData[playerid][BoatLicense],pname);
        mysql_query(query);
        }
    }
}
when player register
pawn Code:
if(dialogid == 1)
    {
        if(response)
        {
            if(!strlen(inputtext))
            {
                SendClientMessage(playerid,red,"ERROR: You need to enter a password!");
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Welcome to Vercetti Gaming Freeroam / Roleplay, Make your password below", "Register", "Leave");
                return 1;
            }
            if(strlen(inputtext) > 32)
            {
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Welcome to Vercetti Gaming Freeroam / Roleplay, Make your password below", "Register", "Leave");
                SendClientMessage(playerid,0xFF9900AA,"Your password is too long please make it less than 32 characters.");
                return 1;
            }
            if(strlen(inputtext) < 3)
            {
                ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "Register", "Welcome to Vercetti Gaming Freeroam / Roleplay, Make your password below", "Register", "Leave");
                SendClientMessage(playerid,0xFF9900AA,"Your password is too long please make it less than 32 characters.");
                return 1;
            }
            CheckMySQL();
            GetPlayerName(playerid, Nam, sizeof(Nam));// now you do it
            mysql_real_escape_string(Nam,escapename);
            format(str, sizeof(str), "SELECT * FROM accounts WHERE Name = '%s'",Nam);
            mysql_query(str);
            mysql_store_result();
            drivingboat[playerid] = 0;
            SetPlayerFightingStyle(playerid,FIGHT_STYLE_NORMAL);
            justconnected[playerid] = 1;
            trucking[playerid] = 0;
            PlayerData[playerid][Interior] = 0;
            shoprobbery[playerid] = 1;
            PlayerData[playerid][Member] = 0;
            god[playerid] = 0;
            PlayerData[playerid][Leader] = 0;
            PlayerData[playerid][PosX] = 0;
            spawned[playerid] = 0;
            PlayerData[playerid][PosY] = 0;
            PlayerData[playerid][PosZ] = 0;
            PlayerData[playerid][IsInOrg] = 0;
            PlayerData[playerid][IsLaw] = 0;
            PlayerData[playerid][phone] = 0;
            PlayerData[playerid][simcard] = 0;
            blowjob[playerid] = 0;
            sex[playerid] = 0;
            PlayerData[playerid][IsGang] = 0;
            PlayerData[playerid][BoatLicense] = 0;
            nos[playerid] = 0;
            fix[playerid] = 0;
            PlayerData[playerid][IsPriv] = 0;
            PlayerData[playerid][Cig] = 0;
            PlayerData[playerid][Sprunk] = 0;
            PlayerData[playerid][Snack] = 0;
            PlayerData[playerid][Lighter] = 0;
            PlayerData[playerid][AdminLevel] = 0;
            PlayerData[playerid][vip] = 0;
            PlayerData[playerid][WantedLevel] = 0;
            PlayerData[playerid][HoursPlayed] = 0;
            PlayerData[playerid][MinutesPlayed] = 0;
            PlayerData[playerid][Cash] = 0;
            PlayerData[playerid][Level] = 0;
            PlayerData[playerid][FightingStyle] = 0;
            PlayerData[playerid][Passport] = 0;
            PlayerData[playerid][Bag] = 0;
            PlayerData[playerid][GunLicense] = 0;
            PlayerData[playerid][Job] = 0;
            selling[playerid] = 0;
            jskin[playerid] = 0;
            civil[playerid] = 0;
            healed[playerid] = 0;
            otest[playerid] = 0;
            died[playerid] = 0;
            PlayerData[playerid][Fuelcan] = 0;
            PlayerData[playerid][Pot] = 0;
            PlayerData[playerid][Crack] = 0;
            PlayerData[playerid][Bank] = 0;
            PlayerData[playerid][MinutesToNextLevel] = 0;
            PlayerData[playerid][phonebook] = 0;
            ad[playerid] = 0;
            carquiz[playerid] = 0;
            cartest[playerid] = 0;
            spray[playerid] = 0;
            PlayerData[playerid][CarLicense] = 0;
            drivingcar[playerid] = 0;
            PlayerData[playerid][Civilskin] = 0;
            PlayerData[playerid][BankAccount] = 0;
            if(mysql_num_rows() == 0)
            {
                mysql_free_result();
                format(str,sizeof(str),"INSERT INTO accounts (Name,Password,Cash) VALUES ('%s','%s',50000)",Nam,inputtext);
                mysql_query(str);
                SendClientMessage(playerid,orange,"You have registered, please now login.");
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Welcome to Vercetti Gaming Freeroam / Roleplay Login with your password", "Login", "Leave");
            }
            else
            {
                SendClientMessage(playerid,orange,"Your account is already registered. Please login.");
                ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Welcome to Vercetti Gaming Freeroam / Roleplay Login with your password", "Login", "Leave");
            }
        }
        if(!response)
        {
            Kick(playerid);
            SendClientMessage(playerid,orange,"You have chosen to leave. Feel free to come back!");
            SendClientMessage(playerid,0xFF9900AA,"_________|174.34.159.19:7781|____________");
        }
        return 1;
    }
on player login
pawn Code:
if(dialogid == 2)
    {
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Welcome to Vercetti Gaming Freeroam / Roleplay Login with your password", "Login", "Leave");
                GetPlayerName(playerid, Nam, sizeof(Nam));
                CheckMySQL();
                mysql_real_escape_string(Nam,escapename);// and here
                mysql_real_escape_string(inputtext,escapepass);// right here
                format(query,sizeof(query),"SELECT * FROM accounts WHERE Name = '%s' AND Password = '%s'",escapename,escapepass);// tan? yes you see inputtext? ya you gonna use myswl_real_escape_string to privent an injection so do it like this
                mysql_query(query);
                mysql_store_result();
                if(mysql_num_rows() == 0)
                {
                    SendClientMessage(playerid,red, "ERROR: You have typed your password wrong!");
                    ShowPlayerDialog(playerid, 2, DIALOG_STYLE_INPUT, "Login", "Welcome to Vercetti Gaming Freeroam / Roleplay Login with your password", "Login", "Leave");
                    return 1;
                }
                mysql_free_result();
                format(file,sizeof(file),"SELECT * FROM accounts WHERE Name = '%s'",escapename);//you don't have to do it here since you already used that function at top there ^^^^
                mysql_query(file);
                mysql_store_result();
                mysql_fetch_row_format(Rows, "|");
                explode(Rows,field, "|");
                mysql_free_result();
                PlayerData[playerid][Name] = strval(field[0]);
                PlayerData[playerid][Password] = strval(field[1]);
                PlayerData[playerid][AdminLevel] = strval(field[2]);
                PlayerData[playerid][Cash] = strval(field[3]);
                PlayerData[playerid][vip] = strval(field[4]);
                PlayerData[playerid][Member] = strval(field[5]);
                PlayerData[playerid][Leader] = strval(field[6]);
                PlayerData[playerid][IsInOrg] = strval(field[7]);
                PlayerData[playerid][IsLaw] = strval(field[8]);
                PlayerData[playerid][IsGang] = strval(field[9]);
                PlayerData[playerid][IsPriv] = strval(field[10]);
                PlayerData[playerid][WantedLevel] = strval(field[11]);
                PlayerData[playerid][MinutesPlayed] = strval(field[12]);
                PlayerData[playerid][HoursPlayed] = strval(field[13]);
                PlayerData[playerid][Level] = strval(field[14]);
                PlayerData[playerid][Cig] = strval(field[15]);
                PlayerData[playerid][Sprunk] = strval(field[16]);
                PlayerData[playerid][Snack] = strval(field[17]);
                PlayerData[playerid][Lighter] = strval(field[18]);
                PlayerData[playerid][FightingStyle] = strval(field[19]);
                PlayerData[playerid][Passport] = strval(field[20]);
                PlayerData[playerid][Bag] = strval(field[21]);
                PlayerData[playerid][GunLicense] = strval(field[22]);
                PlayerData[playerid][Job] = strval(field[23]);
                PlayerData[playerid][Pot] = strval(field[24]);
                PlayerData[playerid][Crack] = strval(field[25]);
                PlayerData[playerid][Bank] = strval(field[26]);
                PlayerData[playerid][BankAccount] = strval(field[27]);
                PlayerData[playerid][CarLicense] = strval(field[28]);
                PlayerData[playerid][Fuelcan] = strval(field[29]);
                PlayerData[playerid][Civilskin] = strval(field[30]);
                PlayerData[playerid][MinutesToNextLevel] = strval(field[31]);
                PlayerData[playerid][simcard] = strval(field[32]);
                PlayerData[playerid][phone] = strval(field[33]);
                PlayerData[playerid][phonebook] = strval(field[34]);
                PlayerData[playerid][PosX] = strval(field[35]);
                PlayerData[playerid][PosY] = strval(field[36]);
                PlayerData[playerid][PosZ] = strval(field[37]);
                PlayerData[playerid][Interior] = strval(field[38]);
                PlayerData[playerid][BoatLicense] = strval(field[39]);
                PayDayTimer[playerid] = SetTimerEx("PayDay",1800000,true,"i",playerid);
                SaveTimer[playerid] = SetTimerEx("Save",10000,true,"i",playerid);
                Logged[playerid] = 1;
                SetPlayerWantedLevel(playerid,PlayerData[playerid][WantedLevel]);
                GivePlayerMoney(playerid,PlayerData[playerid][Cash]);
                SetPlayerScore(playerid,PlayerData[playerid][Level]);
                SetPlayerFightingStyle(playerid,PlayerData[playerid][FightingStyle]);
                SendClientMessage(playerid,orange,"You have logged in and restored your stats.");
                LevelTimer[playerid] = SetTimerEx("LevelTimerr",60000,1,"i",playerid);
                OnlineTimer[playerid] = SetTimerEx("OnlineTimeUpdate", 60000, 1, "i", playerid);
                if(PlayerData[playerid][AdminLevel] == 1)
                {
                    SendClientMessage(playerid,orange,"Welcome back Level 1 Administrator");
                }
                if(PlayerData[playerid][AdminLevel] == 2)
                {
                    SendClientMessage(playerid,orange,"Welcome back Level 2 Administrator");
                }
                if(PlayerData[playerid][AdminLevel] == 3)
                {
                    SendClientMessage(playerid,orange,"Welcome back Level 3 Administrator");
                }
                if(PlayerData[playerid][AdminLevel] == 4)
                {
                    SendClientMessage(playerid,orange,"Welcome back Level 4 Administrator");
                }
                if(PlayerData[playerid][AdminLevel] == 5)
                {
                    SendClientMessage(playerid,orange,"Welcome back Level 5 Administrator");
                }
                if(PlayerData[playerid][Job] == 0)
                {
                    SendClientMessage(playerid,orange,"Job: None");
                }
                if(PlayerData[playerid][Job] == 1)
                {
                    SendClientMessage(playerid,orange,"Job: Arms Dealer");
                }
                if(PlayerData[playerid][Job] == 2)
                {
                    SendClientMessage(playerid,orange,"Job: Whore");
                }
                if(PlayerData[playerid][Job] == 3)
                {
                    SendClientMessage(playerid,orange,"Job: Bus Driver");
                }
                if(PlayerData[playerid][Job] == 4)
                {
                    SendClientMessage(playerid,orange,"Job: Taxi Driver");
                }
                if(PlayerData[playerid][Job] == 5)
                {
                    SendClientMessage(playerid,orange,"Job: Mechanic");
                }
                if(PlayerData[playerid][Job] == 6)
                {
                    SendClientMessage(playerid,orange,"Job: Medic");
                }
                if(PlayerData[playerid][vip] == 1)
                {
                    SendClientMessage(playerid,orange,"VIP Level: Level 1 (Bronze)");
                }
                if(PlayerData[playerid][vip] == 2)
                {
                    SendClientMessage(playerid,orange,"VIP Level: Level 2 (Silver)");
                }
                if(PlayerData[playerid][vip] == 3)
                {
                    SendClientMessage(playerid,orange,"VIP Level: Level 3 (Gold)");
                }
                if(PlayerData[playerid][Member] == 0)
                {
                    SendClientMessage(playerid,orange,"Organization: None.");
                }
                if(PlayerData[playerid][Member] == 1)
                {
                    SendClientMessage(playerid,orange,"Organization: San Andreas Army.");
                }
                if(PlayerData[playerid][Member] == 2)
                {
                    SendClientMessage(playerid,orange,"Organization: Varrios Los Aztecas.");
                }
                if(PlayerData[playerid][Member] == 3)
                {
                    SendClientMessage(playerid,orange,"Organization: Vercetti Trucking Service.");
                }
                if(PlayerData[playerid][Member] == 4)
                {
                    SendClientMessage(playerid,orange,"Organization: San Fierro Rifa.");
                }
                if(PlayerData[playerid][Member] == 5)
                {
                    SendClientMessage(playerid,orange,"Organization: Los Santos Vagos.");
                }
                if(PlayerData[playerid][Member] == 6)
                {
                    SendClientMessage(playerid,orange,"Organization: San Andreas Police Department.");
                }
                if(PlayerData[playerid][Member] == 7)
                {
                    SendClientMessage(playerid,orange,"Organization: Federal Bureau Of Investigation.");
                }
                if(PlayerData[playerid][Member] == 8)
                {
                    SendClientMessage(playerid,orange,"Organization: The Company.");
                }
            }
            if(!response)
            {
            Kick(playerid);
            SendClientMessage(playerid,orange,"You have chosen to leave. Feel free to come back!");
            SendClientMessage(playerid,0xFF9900AA,"_________|174.34.159.19:7781|____________");
            }
    }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)