Mysql help.
#1

I'm trying to make a login&register system and i get some errors .

pawn Код:
//mysql log:

Passing query SELECT id, pass FROM `users` WHERE `name` = `jaw` LIMIT 1 | d
[21:25:41] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
[21:25:41] OnQueryError() - Called.
>> mysql_query_callback( Connection handle: 1 )
[21:25:57] Passing query INSERT INTO `users` (name, pass, money) VALUES ('jaw', '*****', '5000') | d
[21:25:57] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
[21:25:57] OnQueryError() - Called.
pawn Код:
//OnQueryError()

[21:25:41] EID: 1054 | Error: Unknown column 'jaw' in 'where clause' | Query: SELECT id, pass FROM `users` WHERE `name` = `jaw` LIMIT 1
[21:25:57] EID: 1054 | Error: Unknown column 'money' in 'field list' | Query: INSERT INTO `users` (name, pass, money) VALUES ('jaw', '*****', '5000')
pawn Код:
//gamemode

stock CreateAccount(playerid,password[])
{
    new query[128];
    format(query,sizeof(query),"INSERT INTO `users` (name, pass, money) VALUES (\'%s\', \'%s\', \'%d\')",
        returnName(playerid),
        password,
        5000
    );
   
    mysql_function_query(g_Handle, query, false, "OnCreateAccount", "d", playerid);
}
forward OnCreateAccount(playerid);
public OnCreateAccount(playerid)
{
    PlayerInfo[playerid][pID] = mysql_insert_id();
    new loginstring[64];
    format(loginstring,sizeof(loginstring),"Welcome, %s\nThat nick is registered.\nYou can now login:",returnName(playerid));
    ShowPlayerDialog(playerid,12346,DIALOG_STYLE_PASSWORD,"Login",loginstring,"Login","Exit");
    return 1;
}
stock LoadAccount(playerid,password[])
{
    if(strcmp(PlayerInfo[playerid][pKey],password,true) == 0)
    {
        new query[128];
        format(query,sizeof(query),"SELECT * FROM `users` WHERE `id` = `%d`",PlayerInfo[playerid][pID]);
        mysql_function_query(g_Handle, query, true, "OnLoadAccount", "d", playerid);
    }
    else{
        new loginstring[64];
        new loginname[24];
        GetPlayerName(playerid,loginname,sizeof(loginname));
        format(loginstring,sizeof(loginstring),"Wrong Password\nPlease insert the correct password:",loginname);
        ShowPlayerDialog(playerid,12347,DIALOG_STYLE_INPUT,"Login",loginstring,"Login","Exit");
        gPlayerLogTries[playerid] += 1;
        if(gPlayerLogTries[playerid] == 4) { Kick(playerid); }
    }
}
forward OnLoadAccount(playerid);
public OnLoadAccount(playerid)
{
    new temp[40];
   
    cache_get_row(0, 3, temp), PlayerInfo[playerid][pCash] = strval(temp);
    SendClientMessage(playerid,RED,"{FFFFFF}Welcome!");
    GivePlayerMoney(playerid,PlayerInfo[playerid][pCash]);
    return 1;
}
Reply
#2

anyone please?
Reply
#3

format(query,sizeof(query),"SELECT * FROM `users` WHERE `id` = `%d`",PlayerInfo[playerid][pID]);

column names between ticks, values (string values to be precise, though this still works) between single quotes. So, the above line becomes:

format(query,sizeof(query),"SELECT * FROM `users` WHERE `id` = '%d'",PlayerInfo[playerid][pID]);
Reply
#4

Thanks !!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)