Raised This Month: $ Target: $400
 0% 

[HELP] Saving Player steamid to SQL


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SANTO37
Member
Join Date: Aug 2008
Old 06-29-2018 , 16:47   [HELP] Saving Player steamid to SQL
Reply With Quote #1

Hi, I have made a website. I need to record the SteamId information of the players in the base. The steam information will be saved to the database when you write the number / steam.

If the database does not have steam information of the player;
PHP Code:
client_print(idprint_chat"We've already registered you on the system."
If the database also has steam information of the player;
PHP Code:
client_print(idprint_chat"Registration Successful."
I would like to thank the friends who can help me.

In the following code, the information is not saved immediately and the information of other players is added.
This code is not working properly;
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>

// Ur Mysql Information
new Host[]    =    "127.0.0.1"
new User[]    =    "amx_mac"
new Pass[]    =    "amx_mac"
new Db[]    =    "amx_mac"

new Handle:g_SqlTuple
new g_Error[512]
new 
iData[33]

public 
plugin_init() {
    
register_clcmd("say /v""MySql_Init")
}

public 
MySql_Init() {
    
// we tell the API that this is the information we want to connect to,
    // just not yet. basically it's like storing it in global variables
    
g_SqlTuple SQL_MakeDbTuple(Host,User,Pass,Db)
   
    
// ok, we're ready to connect
    
new ErrorCode,Handle:SqlConnection SQL_Connect(g_SqlTuple,ErrorCode,g_Error,charsmax(g_Error))
    if(
SqlConnection == Empty_Handle) {
        
// stop the plugin with an error message
        
set_fail_state(g_Error)
    }
    new 
Handle:Queries
    
// we must now prepare some random queries
    
Queries SQL_PrepareQuery(SqlConnection"CREATE TABLE IF NOT EXISTS tutorial (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, nameid varchar(32), steamid varchar(32), data INT(11))")

    if(!
SQL_Execute(Queries)) {
        
// if there were any problems
        
SQL_QueryError(Queries,g_Error,charsmax(g_Error))
        
set_fail_state(g_Error)
    }
    
    
// close the handle
    
SQL_FreeHandle(Queries)
   
    
// you free everything with SQL_FreeHandle
    
SQL_FreeHandle(SqlConnection)
}

public 
plugin_end() {
    
// free the tuple - note that this does not close the connection,
    // since it wasn't connected in the first place
    
SQL_FreeHandle(g_SqlTuple)
}

public 
Load_MySql(id) {
    new 
szName[32], szSteamId[32], szTemp[512]
    
get_user_authid(id,szSteamId,31)
    
get_user_name(idszName,31)
    
    new 
Data[1]
    
Data[0] = id
    
    
//we will now select from the table `tutorial` where the steamid match
    
format(szTemp,charsmax(szTemp), "SELECT * FROM `tutorial` WHERE (`tutorial`.`nameid` = '%s')"szName)
    
SQL_ThreadQuery(g_SqlTuple"register_client"szTempData1)
}

public 
register_client(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
    if(
FailState == TQUERY_CONNECT_FAILED)
        
log_amx("Load - Could not connect to SQL database.  [%d] %s"ErrcodeError)
    else if(
FailState == TQUERY_QUERY_FAILED)
        
log_amx("Load Query failed. [%d] %s"ErrcodeError)

    new 
id
    id 
Data[0]
    
    if(
SQL_NumResults(Query) < 1) {
        
//.if there are no results found
        
        
new szName[32], szSteamId[32]
        
get_user_authid(idszSteamId,31)    // get user's steamid
        
get_user_name(idszName,31)            // get user's nameid
        
        //  if its still pending we can't do anything with it
        
if (equal(szName"ID_PENDING")) return PLUGIN_HANDLED
        
        
new szTemp[512]
        
// now we will insturt the values into our table.
        
format(szTemp,charsmax(szTemp), "INSERT INTO `tutorial` ( `nameid` , `steamid` , `data`) VALUES ('%s' , '%s' , '0');"szNameszSteamId)
        
SQL_ThreadQuery(g_SqlTuple"IgnoreHandle"szTemp)
    } else {
        
// if there are results found
        
iData[id] = SQL_ReadResult(Query0)
    }
    return 
PLUGIN_HANDLED
}

public 
IgnoreHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {
    
SQL_FreeHandle(Query)
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(idLoad_MySql(id

Last edited by SANTO37; 06-29-2018 at 16:49.
SANTO37 is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:48.


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