SA-MP Forums Archive
Help with mysql - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Help with mysql (/showthread.php?tid=555598)



Help with mysql - bgedition - 08.01.2015

Hey
I need help for account system.
This is the code:
pawn Код:
#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password "r00t"
#define mysql_database "samp"
//--Dialogs
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
//-----Enums
enum pInfo {
    pID,            pLogged,        pPassword,     pLanguage,     pMoney,        pXP,          pTotalXP,     pLevel,
    pVIPLevel,      pAdminLevel,    pKills,        pDeaths,       pMuted,        pMuteTime,    pMuteReason,  pFreezed,
    pFreezeTime,    pFreezeReason,  pJailed,       pJailTime,     pJailReason,   pBanned,      pBanTime,     pBanReason,
    pWarns,         pWarnReason1,   pWarnReason2,  pWarnReason3,  pWarnReason4,  pWarnReason5
}

enum sInfo {
   
}
//-----News
new mysql_handle, PlayerIP[MAX_PLAYERS][16], LAttempts[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][pInfo];
new ServerInfo[MAX_PLAYERS][sInfo];

main() {
}
//-----The GameMode
public OnGameModeInit() {
    SetGameModeText("BGEdition 0.1");
    mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
    mysql_handle = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
    if(mysql_errno(mysql_handle) != 0) print("[ERROR]: Could not connect to database!");
    return 1;
}

public OnGameModeExit() {
    mysql_close(mysql_handle);
    return 1;
}

public OnPlayerConnect(playerid) {
    new Query[300], Rows, Fields, string[300];
    GetPlayerIp(playerid, PlayerIP[playerid], 16);
    mysql_format(mysql_handle, Query, sizeof(Query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
    if(Rows) {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPassword], mysql_handle, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}5 {FFFFFF}attempts to type corect password.", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
    } else {
        format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    new IsLogged[5] = "No";
    PlayerInfo[playerid][pLogged] = strval(IsLogged);
    OnPlayerSave(playerid);
    return 1;
}

public OnPlayerLoad(playerid) {
    cache_get_field_content(0, "Logged", PlayerInfo[playerid][pLogged]);
    cache_get_field_content(0, "Language", PlayerInfo[playerid][pLanguage]);
    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money");
    PlayerInfo[playerid][pXP] = cache_get_field_content_int(0, "XP");
    PlayerInfo[playerid][pTotalXP] = cache_get_field_content_int(0, "Total XP");
    PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
    PlayerInfo[playerid][pVIPLevel] = cache_get_field_content_int(0, "VIP Level");
    PlayerInfo[playerid][pAdminLevel] = cache_get_field_content_int(0, "Admin Level");
    PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
    PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
    cache_get_field_content(0, "Muted", PlayerInfo[playerid][pMuted]);
    cache_get_field_content(0, "Mute TimeStamp", PlayerInfo[playerid][pMuteTime]);
    cache_get_field_content(0, "Mute Reason", PlayerInfo[playerid][pMuteReason]);
    cache_get_field_content(0, "Freezed", PlayerInfo[playerid][pFreezed]);
    cache_get_field_content(0, "Freeze TimeStamp", PlayerInfo[playerid][pFreezeTime]);
    cache_get_field_content(0, "Freeze Reason", PlayerInfo[playerid][pFreezeReason]);
    cache_get_field_content(0, "Jailed", PlayerInfo[playerid][pJailed]);
    cache_get_field_content(0, "Jail TimeStamp", PlayerInfo[playerid][pJailTime]);
    cache_get_field_content(0, "Jail Reason", PlayerInfo[playerid][pJailReason]);
    cache_get_field_content(0, "Banned", PlayerInfo[playerid][pBanned]);
    cache_get_field_content(0, "Ban TimeStamp", PlayerInfo[playerid][pBanTime]);
    cache_get_field_content(0, "Ban Reason", PlayerInfo[playerid][pBanReason]);
    PlayerInfo[playerid][pWarns] = cache_get_field_content_int(0, "Warns");
    cache_get_field_content(0, "Warn Reason 1", PlayerInfo[playerid][pWarnReason1]);
    cache_get_field_content(0, "Warn Reason 2", PlayerInfo[playerid][pWarnReason2]);
    cache_get_field_content(0, "Warn Reason 3", PlayerInfo[playerid][pWarnReason3]);
    cache_get_field_content(0, "Warn Reason 4", PlayerInfo[playerid][pWarnReason4]);
    cache_get_field_content(0, "Warn Reason 5", PlayerInfo[playerid][pWarnReason5]);
    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
    SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
    SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully logged in. Have fun!");
    LAttempts[playerid] = 0;
    return 1;
}

public OnPlayerSave(playerid) {
    new Query[500], string[500];
    format(string, sizeof(string), "UPDATE `players` SET `Language` = %s, `Money` = %d, `XP` = %d, `Total XP` = %d, `Level` = %d, `VIP Level` = %d, `Admin Level` = %d, `Kills` = %d, `Deaths` = %d");
    strcat(string, "`Muted` = %s, `Mute TimeStamp` = %s, `Mute Reason` = %s, `Freezed` = %s, `Freeze TimeStamp` = %s, `Freeze Reason` = %s, `Jailed` = %s, `Jail TimeStamp` = %s, `Jail Reason` = %s");
    strcat(string, "`Banned` = %s, `Ban TimeStamp` = %s, `Ban Reason` = %s, `Warns` = %d, `Warn Reason 1` = %s, `Warn Reason 2` = %s, `Warn Reason 3` = %s, `Warn Reason 4` = %s, `Warn Reason 5` = %s");
    mysql_format(mysql_handle, Query, sizeof(Query), string,
    PlayerInfo[playerid][pLanguage], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pXP], PlayerInfo[playerid][pTotalXP], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIPLevel], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths],
    PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pMuteTime], PlayerInfo[playerid][pMuteReason], PlayerInfo[playerid][pFreezed], PlayerInfo[playerid][pFreezeTime], PlayerInfo[playerid][pFreezeReason], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pJailReason],
    PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pBanTime], PlayerInfo[playerid][pBanReason], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pWarnReason1], PlayerInfo[playerid][pWarnReason2], PlayerInfo[playerid][pWarnReason3], PlayerInfo[playerid][pWarnReason4], PlayerInfo[playerid][pWarnReason5]);
    return 1;
}

public OnPlayerSpawn(playerid) {
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
    return 1;
}

//-----Commands

public OnPlayerText(playerid, text[]) {
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[]) {
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate) {
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    if(dialogid == DIALOG_LOGIN) {
        if(response) {
            new Query[300], string[300];
            if(Hash(inputtext) == PlayerInfo[playerid][pPassword]) {
                mysql_format(mysql_handle, Query, sizeof(Query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
                mysql_tquery(mysql_handle, Query, "OnPlayerLoad", "i", playerid);
            } else {
                LAttempts[playerid] += 1;
                if(LAttempts[playerid] == 1) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}4 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 2) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}3 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 3) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}2 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 4) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nThis is your {FF0000}final {FFFFFF}attempt to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 5) {
                    Kick(playerid);
                }
            }
        } else {
            Kick(playerid);
        }
    }
    if(dialogid == DIALOG_REGISTER) {
        if(response) {
            new Query[300], string[300];
            if(strlen(inputtext) > 5 && strlen(inputtext) < 30) {
                mysql_format(mysql_handle, Query, sizeof(Query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)", GetPName(playerid), Hash(inputtext), PlayerIP[playerid]);
                SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully registered. Have fun!");
                PlayerInfo[playerid][pID] = cache_insert_id();
            } else {
                SendClientMessage(playerid, COLOR_ORANGE, "[WARNING]: Your password needs to be 5 to 30 characters long.");
                format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
                ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
            }
        } else {
            Kick(playerid);
        }
    }
    return 1;
}
This is mysql_log:
Код:
[21:32:53] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "samp", password: "****", port: 3306, autoreconnect: true, pool_size: 2
[21:32:53] [DEBUG] CMySQLHandle::Create - creating new connection..
[21:32:53] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[21:32:53] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:32:53] [DEBUG] mysql_errno - connection: 1
[21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:32:53] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:32:53] [DEBUG] CMySQLConnection::Connect - connection was successful
[21:32:53] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[21:33:13] [DEBUG] mysql_format - connection: 1, len: 300, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1"
[21:33:17] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)"
[21:33:17] [DEBUG] cache_insert_id - connection: 1
[21:33:17] [WARNING] cache_insert_id - no active cache
[21:33:26] [DEBUG] mysql_format - connection: 1, len: 500, format: "UPDATE `players` SET `Language` = , `Money` = , `XP` = , `Total XP` = , `Level` = , `VIP Level` = , `Admin Level` = , `Kills` = ..."
[21:33:30] [DEBUG] mysql_close - connection: 1
[21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[21:33:30] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[21:33:30] [DEBUG] CMySQLHandle::~CMySQLHandle - deconstructor called
When I compile all is right, but when I connect to the server the code isn't work, just open the registration dialog.
I type the password all is right but in database it's not created the table.
The prise if anyone help me: REP +

Sorry for my bad english.


Re: Help with mysql - JeaSon - 08.01.2015

you are not sending query ! you just format the data

use
pawn Код:
mysql_query(mysql_handle, Query, "", "");



Re: Help with mysql - bgedition - 08.01.2015

Thank you so much, Namer.
You helped me to find some mistakes. Some of them are fixed but I need any help to fix reminder. And You are repped!
Quote:
Originally Posted by Namer
Посмотреть сообщение
pawn Код:
mysql_query(mysql_handle, Query, "", "");
must to be:
pawn Код:
mysql_tquery(mysql_handle, Query, "", "");
This is the script:
pawn Код:
/*========= Bulgarian Edition Official GameMode Script Version 0.1 Created By BGEdition ==========*/
//-----Includes
#include <a_samp>
#include <a_mysql>
#include <sscanf>
#include <zcmd>
#include <streamer>
#include <Others>
//-----Defines
//--Mysql
#define mysql_host "127.0.0.1"
#define mysql_user "root"
#define mysql_password "r00t"
#define mysql_database "samp"
//--Dialogs
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
//-----Enums
enum pInfo {
    pID,            pLogged,        pPassword,     pLanguage,     pMoney,         pXP,           pTotalXP,      pLevel,
    pVIPLevel,      pAdminLevel,    pKills,        pDeaths,       pMuted,         pMuteTime,     pMuteReason,   pFreezed,
    pFreezeTime,    pFreezeReason,  pJailed,       pJailTime,     pJailReason,    pBanned,       pBanTime,      pBanReason,
    pBannedIP,      pBanIPTime,     pBanIPReason,  pWarns,        pWarnReason1,   pWarnReason2,  pWarnReason3,  pWarnReason4,
    pWarnReason5,   pFactionID,     pFactionName,  pFactionRID,   pFactionRName,  pBusiness,     pBusinessID,   pHouse,
    pHouseID,       pOffice,        pOfficeID,     pVehicle,      pVehicleID,     pWork,         pWorkID,       pBronzeCups,
    pSilverCups,    pGoldCups
}

enum sInfo {
   
}

//-----News
new mysql_handle, PlayerIP[MAX_PLAYERS][16], LAttempts[MAX_PLAYERS];
new PlayerInfo[MAX_PLAYERS][pInfo];
new ServerInfo[MAX_PLAYERS][sInfo];

main() {
}
//-----The GameMode
public OnGameModeInit() {
    SetGameModeText("BGEdition 0.1");
    mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
    mysql_handle = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
    if(mysql_errno(mysql_handle) != 0) print("[ERROR]: Could not connect to database!");
    return 1;
}

public OnGameModeExit() {
    mysql_close(mysql_handle);
    return 1;
}

public OnPlayerConnect(playerid) {
    new Query[300];
    GetPlayerIp(playerid, PlayerIP[playerid], 16);
    mysql_format(mysql_handle, Query, sizeof(Query),"SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
    mysql_tquery(mysql_handle, Query, "OnPlayerCheck", "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason) {
    new IsLogged[5] = "No";
    PlayerInfo[playerid][pLogged] = strval(IsLogged);
    OnPlayerSave(playerid);
    return 1;
}

public OnPlayerCheck(playerid) {
    new Rows, string[300];
    if(Rows) {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPassword], mysql_handle, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}5 {FFFFFF}attempts to type corect password.", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
    } else {
        format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
    }
    return 1;
}

public OnPlayerRegister(playerid) {
    PlayerInfo[playerid][pID] = cache_insert_id();
    SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully registered. Have fun!");
    return 1;
}

public OnPlayerLoad(playerid) {
    cache_get_field_content(0, "Logged", PlayerInfo[playerid][pLogged]);
    cache_get_field_content(0, "Language", PlayerInfo[playerid][pLanguage]);
    PlayerInfo[playerid][pMoney] = cache_get_field_content_int(0, "Money");
    PlayerInfo[playerid][pXP] = cache_get_field_content_int(0, "XP");
    PlayerInfo[playerid][pTotalXP] = cache_get_field_content_int(0, "Total XP");
    PlayerInfo[playerid][pLevel] = cache_get_field_content_int(0, "Level");
    PlayerInfo[playerid][pVIPLevel] = cache_get_field_content_int(0, "VIP Level");
    PlayerInfo[playerid][pAdminLevel] = cache_get_field_content_int(0, "Admin Level");
    PlayerInfo[playerid][pKills] = cache_get_field_content_int(0, "Kills");
    PlayerInfo[playerid][pDeaths] = cache_get_field_content_int(0, "Deaths");
    cache_get_field_content(0, "Muted", PlayerInfo[playerid][pMuted]);
    cache_get_field_content(0, "Mute TimeStamp", PlayerInfo[playerid][pMuteTime]);
    cache_get_field_content(0, "Mute Reason", PlayerInfo[playerid][pMuteReason]);
    cache_get_field_content(0, "Freezed", PlayerInfo[playerid][pFreezed]);
    cache_get_field_content(0, "Freeze TimeStamp", PlayerInfo[playerid][pFreezeTime]);
    cache_get_field_content(0, "Freeze Reason", PlayerInfo[playerid][pFreezeReason]);
    cache_get_field_content(0, "Jailed", PlayerInfo[playerid][pJailed]);
    cache_get_field_content(0, "Jail TimeStamp", PlayerInfo[playerid][pJailTime]);
    cache_get_field_content(0, "Jail Reason", PlayerInfo[playerid][pJailReason]);
    cache_get_field_content(0, "Banned", PlayerInfo[playerid][pBanned]);
    cache_get_field_content(0, "Ban TimeStamp", PlayerInfo[playerid][pBanTime]);
    cache_get_field_content(0, "Ban Reason", PlayerInfo[playerid][pBanReason]);
    PlayerInfo[playerid][pWarns] = cache_get_field_content_int(0, "Warns");
    cache_get_field_content(0, "Warn Reason 1", PlayerInfo[playerid][pWarnReason1]);
    cache_get_field_content(0, "Warn Reason 2", PlayerInfo[playerid][pWarnReason2]);
    cache_get_field_content(0, "Warn Reason 3", PlayerInfo[playerid][pWarnReason3]);
    cache_get_field_content(0, "Warn Reason 4", PlayerInfo[playerid][pWarnReason4]);
    cache_get_field_content(0, "Warn Reason 5", PlayerInfo[playerid][pWarnReason5]);
    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
    SetPlayerScore(playerid, PlayerInfo[playerid][pLevel]);
    SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: You are successfully logged in. Have fun!");
    LAttempts[playerid] = 0;
    return 1;
}

public OnPlayerSave(playerid) {
    new Query[500], string[500];
    format(string, sizeof(string), "UPDATE `players` SET `Language` = %s, `Money` = %d, `XP` = %d, `Total XP` = %d, `Level` = %d, `VIP Level` = %d, `Admin Level` = %d, `Kills` = %d, `Deaths` = %d");
    strcat(string, "`Muted` = %s, `Mute TimeStamp` = %s, `Mute Reason` = %s, `Freezed` = %s, `Freeze TimeStamp` = %s, `Freeze Reason` = %s, `Jailed` = %s, `Jail TimeStamp` = %s, `Jail Reason` = %s");
    strcat(string, "`Banned` = %s, `Ban TimeStamp` = %s, `Ban Reason` = %s, `Warns` = %d, `Warn Reason 1` = %s, `Warn Reason 2` = %s, `Warn Reason 3` = %s, `Warn Reason 4` = %s, `Warn Reason 5` = %s");
    mysql_format(mysql_handle, Query, sizeof(Query), string,
    PlayerInfo[playerid][pLanguage], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pXP], PlayerInfo[playerid][pTotalXP], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIPLevel], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths],
    PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pMuteTime], PlayerInfo[playerid][pMuteReason], PlayerInfo[playerid][pFreezed], PlayerInfo[playerid][pFreezeTime], PlayerInfo[playerid][pFreezeReason], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pJailReason],
    PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pBanTime], PlayerInfo[playerid][pBanReason], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pWarnReason1], PlayerInfo[playerid][pWarnReason2], PlayerInfo[playerid][pWarnReason3], PlayerInfo[playerid][pWarnReason4], PlayerInfo[playerid][pWarnReason5]);
    mysql_tquery(mysql_handle, Query, "", "");
    return 1;
}

public OnPlayerSpawn(playerid) {
    SetPlayerColor(playerid, 0xFF0000FF);
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason) {
    return 1;
}

//-----Commands

public OnPlayerText(playerid, text[]) {
    new string[500];
    format(string, sizeof(string), "{%h}%s{FFFFFF}[%d]: %s", GetPlayerColor(playerid) >>> 8, GetPName(playerid), playerid, ColoredText(text[0]));
    SendClientMessageToAll(-1, string);
    return 0;
}

public OnPlayerCommandText(playerid, cmdtext[]) {
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate) {
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    if(dialogid == DIALOG_LOGIN) {
        if(response) {
            new Query[300], string[300];
            if(Hash(inputtext) == PlayerInfo[playerid][pPassword]) {
                mysql_format(mysql_handle, Query, sizeof(Query), "SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1", GetPName(playerid));
                mysql_tquery(mysql_handle, Query, "OnPlayerLoad", "i", playerid);
            } else {
                LAttempts[playerid] += 1;
                if(LAttempts[playerid] == 1) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}4 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 2) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}3 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 3) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}2 {FFFFFF}attempts to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 4) {
                    format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nThis is your {FF0000}final {FFFFFF}attempt to type corect password.", GetPName(playerid));
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
                } else if(LAttempts[playerid] == 5) {
                    Kick(playerid);
                }
            }
        } else {
            Kick(playerid);
        }
    }
    if(dialogid == DIALOG_REGISTER) {
        if(response) {
            new Query[300], string[300];
            if(strlen(inputtext) > 5 && strlen(inputtext) < 30) {
                mysql_format(mysql_handle, Query, sizeof(Query), "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)", GetPName(playerid), Hash(inputtext), PlayerIP[playerid]);
                mysql_tquery(mysql_handle, Query, "OnPlayerRegister", "i", playerid);
            } else {
                SendClientMessage(playerid, COLOR_ORANGE, "[WARNING]: Your password needs to be 5 to 30 characters long.");
                format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
                ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
            }
        } else {
            Kick(playerid);
        }
    }
    return 1;
}
and the mysql_log:
Код:
[17:59:16] [DEBUG] mysql_connect - host: "127.0.0.1", user: "root", database: "samp", password: "****", port: 3306, autoreconnect: true, pool_size: 2
[17:59:16] [DEBUG] CMySQLHandle::Create - creating new connection..
[17:59:16] [DEBUG] CMySQLHandle::CMySQLHandle - constructor called
[17:59:16] [DEBUG] CMySQLHandle::Create - connection created (id: 1)
[17:59:16] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[17:59:16] [DEBUG] CMySQLConnection::Connect - connection was successful
[17:59:16] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[17:59:16] [DEBUG] mysql_errno - connection: 1
[17:59:16] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[17:59:16] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[17:59:16] [DEBUG] CMySQLConnection::Connect - establishing connection to database...
[17:59:16] [DEBUG] CMySQLConnection::Connect - connection was successful
[17:59:16] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[17:59:16] [DEBUG] CMySQLConnection::Connect - connection was successful
[17:59:16] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[17:59:16] [DEBUG] CMySQLConnection::Connect - connection was successful
[17:59:16] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[17:59:37] [DEBUG] mysql_format - connection: 1, len: 300, format: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = '%e' LIMIT 1"
[17:59:37] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `Password`, `ID` FROM `players` WHERE `Username` = 'BGEdi", callback: "OnPlayerCheck", format: "i"
[17:59:37] [DEBUG] CMySQLQuery::Execute[OnPlayerCheck] - starting query execution
[17:59:37] [DEBUG] CMySQLQuery::Execute[OnPlayerCheck] - query was successfully executed within 0.444 milliseconds
[17:59:37] [DEBUG] CMySQLResult::CMySQLResult() - constructor called
[17:59:37] [DEBUG] Calling callback "OnPlayerCheck"..
[17:59:37] [DEBUG] CMySQLResult::~CMySQLResult() - deconstructor called
[17:59:41] [DEBUG] mysql_format - connection: 1, len: 300, format: "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`%e`, `%s`, `%s`)"
[17:59:41] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `players` (`Username`, `Password`, `IP`) VALUES (`BG", callback: "OnPlayerRegister", format: "i"
[17:59:41] [DEBUG] CMySQLQuery::Execute[OnPlayerRegister] - starting query execution
[17:59:41] [ERROR] CMySQLQuery::Execute[OnPlayerRegister] - (error #1054) Unknown column 'BGEdition' in 'field list'
[17:59:41] [DEBUG] CMySQLQuery::Execute[OnPlayerRegister] - error will be triggered in OnQueryError
[17:59:41] [DEBUG] Calling callback "OnQueryError"..
[17:59:45] [DEBUG] mysql_format - connection: 1, len: 500, format: "UPDATE `players` SET `Language` = , `Money` = , `XP` = , `Total XP` = , `Level` = , `VIP Level` = , `Admin Level` = , `Kills` = ..."
[17:59:45] [DEBUG] mysql_tquery - connection: 1, query: "UPDATE `players` SET `Language` = , `Money` = , `XP` = , `Total ", callback: "(null)", format: "(null)"
[17:59:45] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[17:59:45] [ERROR] CMySQLQuery::Execute[] - (error #1064) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' `Money` = , `XP` = , `Total XP` = , `Level` = , `VIP Level` = , `Admin Level` =' at line 1
[17:59:45] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError
[17:59:45] [DEBUG] Calling callback "OnQueryError"..
[17:59:48] [DEBUG] mysql_close - connection: 1
[17:59:48] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[17:59:48] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[17:59:48] [DEBUG] CMySQLConnection::Disconnect - connection was closed
[17:59:49] [DEBUG] CMySQLHandle::~CMySQLHandle - deconstructor called
database screenshots:
http://prntscr.com/5pyync
http://prntscr.com/5pyysi


Re: Help with mysql - JeaSon - 08.01.2015

always remember that if there is a string you need to use it like this

examples
pawn Код:
Language = '%s'
not like this

pawn Код:
Language = %s
here fix for update

pawn Код:
public OnPlayerSave(playerid) {
    new Query[500], string[500];
    format(string, sizeof(string), "UPDATE `players` SET `Language` = '%s', `Money` = %d, `XP` = %d, `Total XP` = %d, `Level` = %d, `VIP Level` = %d, `Admin Level` = %d, `Kills` = %d, `Deaths` = %d");
    strcat(string, "`Muted` = '%s', `Mute TimeStamp` = '%s', `Mute Reason` = '%s', `Freezed` = '%s', `Freeze TimeStamp` = '%s', `Freeze Reason` = '%s', `Jailed` = '%s', `Jail TimeStamp` = '%s', `Jail Reason` = '%s'");
    strcat(string, "`Banned` = '%s', `Ban TimeStamp` = '%s', `Ban Reason` = '%s', `Warns` = %d, `Warn Reason 1` = '%s', `Warn Reason 2` = '%s', `Warn Reason 3` = '%s', `Warn Reason 4` = '%s', `Warn Reason 5` = '%s'");
    mysql_format(mysql_handle, Query, sizeof(Query), string,
    PlayerInfo[playerid][pLanguage], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pXP], PlayerInfo[playerid][pTotalXP], PlayerInfo[playerid][pLevel], PlayerInfo[playerid][pVIPLevel], PlayerInfo[playerid][pAdminLevel], PlayerInfo[playerid][pKills], PlayerInfo[playerid][pDeaths],
    PlayerInfo[playerid][pMuted], PlayerInfo[playerid][pMuteTime], PlayerInfo[playerid][pMuteReason], PlayerInfo[playerid][pFreezed], PlayerInfo[playerid][pFreezeTime], PlayerInfo[playerid][pFreezeReason], PlayerInfo[playerid][pJailed], PlayerInfo[playerid][pJailTime], PlayerInfo[playerid][pJailReason],
    PlayerInfo[playerid][pBanned], PlayerInfo[playerid][pBanTime], PlayerInfo[playerid][pBanReason], PlayerInfo[playerid][pWarns], PlayerInfo[playerid][pWarnReason1], PlayerInfo[playerid][pWarnReason2], PlayerInfo[playerid][pWarnReason3], PlayerInfo[playerid][pWarnReason4], PlayerInfo[playerid][pWarnReason5]);
    mysql_tquery(mysql_handle, Query, "", "");
    return 1;
}
tell me if there again error ouccors


Re: Help with mysql - bgedition - 09.01.2015

OK thank you. Now it work.
The ERROR "SQL syntax" - I forgot to add two commas in "OnPlayerSave" on the end of format and the first strcat.
But some rows isn't work. Including password and I can't login.
Help me !


Re: Help with mysql - JeaSon - 09.01.2015

you are not getting the data

try this

pawn Код:
public OnPlayerCheck(playerid) {
    new rows ,fields ,string[300];
    cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database.
    if(rows) {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPassword], mysql_handle, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}5 {FFFFFF}attempts to type corect password.", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
    } else {
        format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
    }
    return 1;
}



Re: Help with mysql - bgedition - 09.01.2015

Still the same


Re: Help with mysql - JeaSon - 09.01.2015

my bad i did
pawn Код:
cache_get_data(rows, fields, mysql);//let's get the rows and fields from the database.
mysql should be mysql_handle
try now


pawn Код:
public OnPlayerCheck(playerid) {
    new rows ,fields ,string[300];
    cache_get_data(rows, fields, mysql_handle);//let's get the rows and fields from the database.
    if(rows) {
        cache_get_field_content(0, "Password", PlayerInfo[playerid][pPassword], mysql_handle, 129);
        PlayerInfo[playerid][pID] = cache_get_field_content_int(0, "ID");
        format(string, sizeof(string), "{FFFFFF}Welcome back {2098AE}%s {FFFFFF}!\nType your password below to login!\nYou have only {FF0000}5 {FFFFFF}attempts to type corect password.", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_LOGIN, 3, "{FFFF00}Loging in:", string, "Login", "Cancel");
    } else {
        format(string, sizeof(string), "{FFFFFF}Welcome {2098AE}%s {FFFFFF}!\nType password below into the input to register!\nThe password must to be 5 to 30 characters long!", GetPName(playerid));
        ShowPlayerDialog(playerid, DIALOG_REGISTER, 3, "{FFFF00}Registering:", string, "Register", "Cacnel");
    }
    return 1;
}



Re: Help with mysql - bgedition - 09.01.2015

I know it.
EDIT: It's still doesn't work.


Re: Help with mysql - bgedition - 09.01.2015

Any ideas?