MySQL Query Errors.
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
Not sure about the UPDATE query but you should seriously change the way you save. Name does not change unless it is done by the script, so does password; thus those need to be updated when necessary and not every time a player disconnects.

About the INSERT query, you have more columns than 2 in the table. You can avoid writing the columns but you have to specify all the values (unless there are default values which you can ignore and those should be always last). For now, add the name and password columns along with the query.
I'm still learning MySQL, so I'm not great with it. However, I found that I made a mistake on these codes (I wrote ' ' on the queries instead of ` `) and I solved it, but I got another errors and gonna post it below.

Inserting Query Codes - DIALOG:
pawn Код:
case 1:
        {
            if(response)
            {
                new query[126], pName[MAX_PLAYER_NAME];
                GetPlayerName(playerid, pName, sizeof(pName));

                format(query, sizeof(query), "INSERT INTO accounts VALUES (`%s`, `%s`)", pName, inputtext);
                mysql_query(query);
                SendClientMessage(playerid, COLOR_WHITE, "You have successfully registered into the server!");

                SetSpawnInfo(playerid, 1, 299, 1, 2, 3, 1, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
            }
        }
Errors while inserting into the DB:
pawn Код:
[18:50:42] CMySQLHandler::Query(INSERT INTO accounts VALUES (`Steve_Malcom`, `passytest`)) - An error has occured. (Error ID: 1054, Unknown column 'Steve_Malcom' in 'field list')
Updating Query Codes:
pawn Код:
stock SavePlayer(playerid)
{
    new query[126], pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));

    GetPlayerPos(playerid, Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2]);

    format(query, sizeof(query), "UPDATE accounts SET Name = `%s`, Password = `%s`, PlayerX = `%f`, PlayerY = `%f`, PlayerZ = `%f` WHERE Name = `%s`", pName, Player[playerid][Password], Player[playerid][Position][0], Player[playerid][Position][1], Player[playerid][Position][2], pName);
    mysql_query(query);

    printf("[server] Player ID %d (%s) has been saved into the database.", playerid, pName);
}
Errors while attempt to update in queries:
pawn Код:
[18:50:49] CMySQLHandler::Query(UPDATE accounts SET Name = `Steve_Malcom`, Password = ``, PlayerX = `1958.378295`, PlayerY = `1343.157226`, PlayerZ = `15.3) - An error has occured. (Error ID: 1054, Unknown column 'Steve_Malcom' in 'field list')
Am I getting these errors, because of the other three columns which they are PlayerX, PlayerY and PlayerZ?
Reply


Messages In This Thread
MySQL Query Errors. - by Shady - 13.07.2016, 16:45
Re: MySQL Query Errors. - by Konstantinos - 13.07.2016, 16:53
Re: MySQL Query Errors. - by Shady - 13.07.2016, 16:59
Re: MySQL Query Errors. - by Konstantinos - 13.07.2016, 17:02
Re: MySQL Query Errors. - by Shady - 13.07.2016, 17:11
Re: MySQL Query Errors. - by PrO.GameR - 13.07.2016, 19:49
Re: MySQL Query Errors. - by SickAttack - 13.07.2016, 20:22
Re: MySQL Query Errors. - by Shady - 13.07.2016, 22:52
Re: MySQL Query Errors. - by Ghazal - 13.07.2016, 23:06
Re: MySQL Query Errors. - by Shady - 13.07.2016, 23:14
Re: MySQL Query Errors. - by DRIFT_HUNTER - 13.07.2016, 23:25
Re: MySQL Query Errors. - by ItzShady - 13.07.2016, 23:36
Re: MySQL Query Errors. - by SyS - 14.07.2016, 01:16
Re: MySQL Query Errors. - by SickAttack - 14.07.2016, 01:41
Re: MySQL Query Errors. - by WhiteGhost - 14.07.2016, 01:43
Re: MySQL Query Errors. - by SyS - 14.07.2016, 02:24
Re: MySQL Query Errors. - by SickAttack - 14.07.2016, 02:39
Re: MySQL Query Errors. - by DRIFT_HUNTER - 14.07.2016, 02:52
Re: MySQL Query Errors. - by ItzShady - 14.07.2016, 02:53
Re: MySQL Query Errors. - by SyS - 14.07.2016, 08:23

Forum Jump:


Users browsing this thread: 1 Guest(s)