Raised This Month: $ Target: $400
 0% 

[ISSUE] Problem while storing data in the database


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 05-08-2020 , 15:45   [ISSUE] Problem while storing data in the database
Reply With Quote #1

So,

What I am trying to do is really simple

Store the name, steamid and IP on the database when he joins the server. But, when connecting I want to the plugin to check if the player is already registered. So, we get the IP that is stored on the database for the player's steamid. If the database player's IP does not match to the actual player's IP, I want it to write a new line with new data, as such the name, steamID and iP.

The problem is that it is not storing any data.

PHP Code:
#pragma semicolon 1

#define DEBUG

#define PLUGIN_AUTHOR "SpirT"
#define PLUGIN_VERSION "1.0"

#include <sourcemod>
#include <sdktools>

Database DB null;
char Error[256];

#pragma newdecls required

public Plugin myinfo 
{
    
name "[SpirT - Database Query]",
    
author PLUGIN_AUTHOR,
    
description "",
    
version PLUGIN_VERSION,
    
url ""
};

public 
void OnPluginStart()
{
    
DB SQL_Connect("spirtdb"trueErrorsizeof(Error));
    
    if(
DB == null)
    {
        
PrintToServer("[DB] Cannot connect to MySQL Server: %s"Error);
        
CloseHandle(DB);
    }
    else
    {
        
PrintToServer("[DB] Connection Successful");
        
char squery[256];
        
Format(squerysizeof(squery), "CREATE TABLE IF NOT EXISTS players (name varchar(32) NOT NULL, steamid varchar(32) NOT NULL, ip varchar(64) NOT NULL)");
        if(!
SQL_FastQuery(DBsquery))
        {
            
char terror[256];
            
SQL_GetError(DBterrorsizeof(terror));
            
PrintToServer("[DB] Could not create db tables. Error: %s"terror);
        }
        else
        {
            
PrintToServer("[DB] Tables Created if they don't exist.");
        }
    }
}

public 
void OnClientPutInServer(int client)
{
    
char iname[32];
    
GetClientName(clientinamesizeof(iname));
    
    
char iid[32];
    
GetClientAuthId(clientAuthId_Steam2iidsizeof(iid));
    
    
char iip[64];
    
GetClientIP(clientiipsizeof(iip), true);
    
    
char squery[256];
    
Format(squerysizeof(squery), "SELECT ip FROM players WHERE steamid = '%s'"iid);
    
DBResultSet select SQL_Query(DBsquery);
    
    if(
select == null)
    {
        
PrintToServer("[DB] Could not get data from the database.");
        return;
    }
    
    
char dbIP[64];
    
SQL_FetchString(DB0dbIPsizeof(dbIP));
    
    if(
StrEqual(dbIPiip))
    {
        
PrintToServer("[DB] Player is already saved on the database.");
        return;
    }
    
    
char newquery[256];
    
Format(newquerysizeof(newquery), "INSERT INTO players (name, steamid, ip) VALUES ('%s', '%s', '%s')"inameiidiip);
    
DBResultSet query2 SQL_Query(DBnewquery);
    if(
query2 == null)
    {
        
PrintToServer("[DB] Could not save new player data.");
        return;
    }
    
    
PrintToServer("[DB] New player data was save in the database with success.");
    return;

Any solution for the plugin to fix my issue?

OBS: That plugin was storing the player data EVERYTIME he joined the server, so I tried to update it to a more NON-SPAMMING version. This "new update" on the source above is creating the tables but not storing data.

Best Regards,

SpirT.
__________________
SpirT is offline
 



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 10:13.


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