AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   sql problem (https://forums.alliedmods.net/showthread.php?t=56009)

CipryXXX 06-04-2007 09:04

sql problem
 
i tryd to make for me a punish sistem like v3x`s but i wanted mine with sql but i cant compile the plugin :(
pls help me with this problem i dont know why i get this errors
:
Code:

/home/groups/amxmodx/tmp3/phpDQnORL.sma(16) : warning 213: tag mismatch
/home/groups/amxmodx/tmp3/phpDQnORL.sma(24) : error 017: undefined symbol "connect"
/home/groups/amxmodx/tmp3/phpDQnORL.sma(30) : error 035: argument type mismatch (argument 1)
/home/groups/amxmodx/tmp3/phpDQnORL.sma(42) : warning 204: symbol is assigned a value that is never used: "charname"
/home/groups/amxmodx/tmp3/phpDQnORL.sma(42) : warning 209: function "insert" should return a value
/home/groups/amxmodx/tmp3/phpDQnORL.sma(54) : error 017: undefined symbol "connect"
/home/groups/amxmodx/tmp3/phpDQnORL.sma(63) : error 035: argument type mismatch (argument 1)
/home/groups/amxmodx/tmp3/phpDQnORL.sma(72) : warning 204: symbol is assigned a value that is never used: "charname"
/home/groups/amxmodx/tmp3/phpDQnORL.sma(73) : warning 209: function "punish" should return a value

source :
Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <dbi>

#define PLUGIN "Plugin"
#define VERSION "1.0"
#define AUTHOR "CipryXXX"


public plugin_init() {
    register_plugin(PLUGIN, VERSION, AUTHOR)
    set_task(0.1,"conexiune")
    set_task(1,"punish")
    register_concmd("amx_insert_nick","insert",ADMIN_LEVEL_C,"Inserts a players nickname in the punish user database")
}
public insert(id)
{
    new name[100]
    new charname
    charname = get_user_name(id,name,99)
    if (connect == SQL_FAILED)
    {
        return PLUGIN_HANDLED;
    }
    else
    {
        new Result:result = dbi_query("INSERT INTO user (nume) VALUES ('%s')",charname)
        if(result == RESULT_FAILED)
        {
            log_amx("[MySQL] Coud not insert username in data base!!")
        }
        else
        {
            return PLUGIN_HANDLED;
        }
    }
           
   
}
public conexiune()
{
    new error[255]
    new Sql:connect = dbi_connect("localhost","root","","ban",error,254)
    if(connect==SQL_FAILED)
    {
        log_amx("[MySQL] SQL Connection Failed = %s", error)
    }
}
public punish(id)
{
    if (connect == SQL_FAILED)
    {
        return PLUGIN_HANDLED;
    }
    else
    {
        new name[100]
        new charname
        charname = get_user_name(id,name,99)
        new Result:result = dbi_query("SELECT nume FROM user WHERE nume = '%s'",charname)
        if(result == RESULT_FAILED)
        {
            log_amx("[MySQL] Select username failed!!")
        }
        else
        {
            set_user_health(id,1) //not finished.
        }
    }
}


Sylwester 06-04-2007 11:50

Re: sql problem
 
fixed errors
How to use dbi: http://forums.alliedmods.net/showthread.php?p=24962
You can also use sqlx isntead of dbi: http://forums.alliedmods.net/showthread.php?t=46779
Next time when you get error on some function, check it in http://www.amxmodx.org/funcwiki.php

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <dbi>

#define PLUGIN "Plugin"
#define VERSION "1.0"
#define AUTHOR "CipryXXX"

new Sql:connect

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
set_task(0.1,"conexiune")
    
set_task(1.0,"punish")
    
register_concmd("amx_insert_nick","insert",ADMIN_LEVEL_C,"Inserts a players nickname in the punish user database")
}

public 
insert(id)
{
    new 
name[100]
    new 
charname
    charname 
get_user_name(id,name,99)
    if (
connect == SQL_FAILED)
    {
        return 
PLUGIN_HANDLED;
    }
    else
    {
        new 
Result:result dbi_query(connect"INSERT INTO user (nume) VALUES ('%s')",charname)
        if(
result == RESULT_FAILED)
        {
            
log_amx("[MySQL] Coud not insert username in data base!!")
        }
        else
        {
            return 
PLUGIN_HANDLED;
        }
    }
            
    return 
PLUGIN_HANDLED;
}

public 
conexiune()
{
    new 
error[255]
    
connect dbi_connect("localhost","root","","ban",error,254)
    if(
connect==SQL_FAILED)
    {
        
log_amx("[MySQL] SQL Connection Failed = %s"error)
    }
}
public 
punish(id)
{
    if (
connect == SQL_FAILED)
    {
        return 
PLUGIN_HANDLED;
    }
    else
    {
        new 
name[100]
        new 
charname
        charname 
get_user_name(id,name,99)
        new 
Result:result dbi_query(connect"SELECT nume FROM user WHERE nume = '%s'",charname)
        if(
result == RESULT_FAILED)
        {
            
log_amx("[MySQL] Select username failed!!")
        }
        else
        {
            
set_user_health(id,1//not finished.
        
}
    }
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 10:43.

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