AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Whats wrong in this mysql? (https://forums.alliedmods.net/showthread.php?t=331984)

jonatat 04-17-2021 05:44

Whats wrong in this mysql?
 
I need to kick player if they STEAMID are not in database.

PHP Code:

public client_authorized(id

new 
auth[32]; 
get_user_authid(idauthsizeof (auth));

new 
Handle:query SQL_PrepareQuery(g_sql"SELECT `steam_id` FROM `users` WHERE (`steam_id` = '%s')"auth); 
SQL_Execute(query); 

new 
res[32]; 

if (
SQL_MoreResults(query)) 

SQL_ReadResult(query0ressizeof (res)); 
SQL_FreeHandle(query); 


if (!
strlen(res)) 

server_cmd("kick #%i %s"get_user_userid(id), restrict_msg); 



But i'm allways getting kick. Any suggestions what im doing wrong?

jonatat 04-17-2021 06:48

Re: Whats wrong in this mysql?
 
Any help?

Shadows Adi 04-17-2021 09:55

Re: Whats wrong in this mysql?
 
Try this:
PHP Code:

public client_putinserver(id// In this phase the user can be affected by the commands
{
    new 
auth[32]; 
    
get_user_authid(idauthsizeof (auth));

    new 
Handle:query SQL_PrepareQuery(g_sql"SELECT * FROM `users` WHERE (`steam_id` = '%s')"auth); 
    
SQL_Execute(query); 

    if (!
SQL_NumResultsquery)) // If no results found, kick the player
    

        
server_cmd("kick #%i ^"%s^""get_user_userid(id), restrict_msg); 
    }
    
SQL_FreeHandle(query); // Free the query



jonatat 04-17-2021 13:08

Re: Whats wrong in this mysql?
 
Quote:

Originally Posted by Shadows Adi (Post 2744325)
Try this:
PHP Code:

public client_putinserver(id// In this phase the user can be affected by the commands
{
    new 
auth[32]; 
    
get_user_authid(idauthsizeof (auth));

    new 
Handle:query SQL_PrepareQuery(g_sql"SELECT * FROM `users` WHERE (`steam_id` = '%s')"auth); 
    
SQL_Execute(query); 

    if (!
SQL_NumResultsquery)) // If no results found, kick the player
    

        
server_cmd("kick #%i ^"%s^""get_user_userid(id), restrict_msg); 
    }
    
SQL_FreeHandle(query); // Free the query



Same problem... I dont get it why...

Shadows Adi 04-17-2021 15:20

Re: Whats wrong in this mysql?
 
Show full code.

Bugsy 04-17-2021 15:23

Re: Whats wrong in this mysql?
 
Try this:
PHP Code:

new szError64 ];
if ( !
SQL_Executequery ) )
{
    
SQL_QueryErrorquery szError charsmaxszError ) );
    
set_fail_stateszError );



LondoN 04-19-2021 03:54

Re: Whats wrong in this mysql?
 
Code:

public client_connect(id)
{
        new g_szAuthID[32];
        get_user_authid(id, g_szAuthID, charsmax(g_szAuthID));

        new g_szQuery[256];
        formatex(g_szQuery, charsmax(g_szQuery), "SELECT * FROM tablename WHERE player_auth = '%s'", g_szAuthID);

        new g_szData[1];
        g_szData[0] = id;

        SQL_ThreadQuery(g_SQLTuple, "SQL_Check", g_szQuery, g_szData, sizeof g_szData);
}

public SQL_Check(FailState, Handle: Query, szError[], iErrorCode, szData[], iDataSize)
{
        if(!FailState && !iErrorCode)
        {
                new id = szData[0];

                if(!SQL_NumResults(Query))
                        server_cmd("kick #%d", get_user_userid(id));
        }

        SQL_FreeHandle(Query);
}

This type of 'doing sql' always worked fine for me, you can try.


All times are GMT -4. The time now is 17:15.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.