SA-MP Forums Archive
cache_insert_id is always 0 - 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: cache_insert_id is always 0 (/showthread.php?tid=603374)



cache_insert_id is always 0 - BornHuman - 22.03.2016

pawn Код:
// under DIALOG_REGISTER
mysql_format(SQL, Query, sizeof(Query), "INSERT INTO `Accounts` (`Username`, `Password`) VALUES ('%e', '%e')", GetNameWithUnderscore(playerid), Player[playerid][Password]);
            mysql_tquery(SQL, Query, "OnPlayerRegisterAccount", "i", playerid);
pawn Код:
public OnPlayerRegisterAccount(playerid)
{
    Player[playerid][DatabaseID] = cache_insert_id();
    printf("[SQL] New account registered. Database ID: [%d]", cache_insert_id());

    new pIP[16], Query[255];
    GetPlayerIp(playerid, pIP, sizeof(pIP));
   
    mysql_format(SQL, Query, sizeof(Query), "UPDATE `accounts` SET `RegisterIP` = %s, \
        WHERE `DatabaseID` = %d"
, pIP, Player[playerid][DatabaseID]); // I'm also getting a MYSQL error here
    mysql_tquery(SQL, Query, "", "");

    AdvanceTutorial(playerid, 1);
    return 1;
}
cache_insert_id and Player[playerid][DatabaseID] always returns 0.

Halp pls (REP+)


Re: cache_insert_id is always 0 - Konstantinos - 22.03.2016

The column in the db should be set with AUTO_INCREMENT.


Re: cache_insert_id is always 0 - BornHuman - 22.03.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
The column in the db should be set with AUTO_INCREMENT.
Thank you! I forgot to do that when I was setting up my db. Rookie mistake.

I'm going to test it. REP+