Mysql error.
#1

Hello, everyone.

I decided to learn mysql and my log is giving me an error. I'm trying to make a registration system and when a player connects - the dialog doesn't show. I read the log, and it looks like a string issue with my username, but I'm not entirely sure.


Here's the log.
Код:
[22:38:09] [DEBUG] CMySQLConnection::Connect - auto-reconnect has been enabled
[22:38:35] [DEBUG] mysql_format - connection: 1, len: 128, format: "SELECT `pPass`, `pID` FROM `players` WHERE `Username` = `%e` LIMIT 1"
[22:38:35] [DEBUG] mysql_tquery - connection: 1, query: "SELECT `pPass`, `pID` FROM `players` WHERE `Username` = `Rangerx", callback: "OnAccountCheck", format: "i"
[22:38:35] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - starting query execution
[22:38:35] [ERROR] CMySQLQuery::Execute[OnAccountCheck] - (error #1054) Unknown column 'Rangerxxll' in 'where clause'
[22:38:35] [DEBUG] CMySQLQuery::Execute[OnAccountCheck] - error will be triggered in OnQueryError
And this is relevant code. I decided to follow a tutorial (I wrote all the code by hand for hands-on practice.) If you need anymore code, please let me know. Thank you.

pawn Код:
public OnPlayerConnect(playerid)
{
    new query[128], ip[16];
    GetPlayerName(playerid, Name[playerid],24);
    GetPlayerIp(playerid, ip, sizeof(ip));
    mysql_format(mysql, query, sizeof(query), "SELECT `pPass`, `pID` FROM `players` WHERE `Username` = `%e` LIMIT 1", Name[playerid]);
    mysql_tquery(mysql, query, "OnAccountCheck", "i", playerid);
    return 1;
}



forward OnAccountCheck(playerid);
public OnAccountCheck(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields, mysql);
    if(rows)
    {
        cache_get_field_content(0, "pPass", pInfo[playerid][pPass], mysql, 129);
        pInfo[playerid][pID] = cache_get_field_content_int(0, "pID");
        printf("%s", pInfo[playerid][pPass]);
        ShowPlayerDialog(playerid, REGISTER_LOGIN, DIALOG_STYLE_INPUT, "Login", "In order to play, you need to login", "Login", "Quit");
    }
    else
    {
        ShowPlayerDialog(playerid, REGISTER_REGISTER, DIALOG_STYLE_INPUT, "Register", "In order to play, you need to register.", "Register", "Quit");
    }
    return 1;
}
Reply
#2

Corrected your query, Use this:
PHP код:
public OnPlayerConnect(playerid)
{
    new 
query[128], ip[16];
    
GetPlayerName(playeridName[playerid],24);
    
GetPlayerIp(playeridipsizeof(ip));
    
mysql_format(mysqlquerysizeof(query), "SELECT `pPass`, `pID` FROM `players` WHERE `Username` = '%e' LIMIT 1"Name[playerid]);
    
mysql_tquery(mysqlquery"OnAccountCheck""i"playerid);
    return 
1;

You should use ( '%e' ) instead of ( `%e` )
Always use the quotes: (' ') for strings / escaped strings, and the quotes (` `) for columns.
Reply
#3

Is there anything specific I should use for an integer?

EDIT: Thank you. Corrected a few more string mistakes and my login/register system seems to be working. Going to keep experimenting. If you could explain how rows, fields, entries, all work that would be great. I've looked at a few tutorials and they seem to lack that.
Reply
#4

Is this newbienoob's tutorial?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)