Raised This Month: $ Target: $400
 0% 

sql problem


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-04-2007 , 11:50   Re: sql problem
Reply With Quote #2

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;

__________________
Impossible is Nothing
Sylwester 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:43.


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