AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Register in the SQL if not already there? (https://forums.alliedmods.net/showthread.php?t=50193)

blackops7799 01-21-2007 13:45

Register in the SQL if not already there?
 
Well I run a Zombie TS Server. Is there a way to check is a joining player is in the SQL, and if he is not it will add him?

I know it has something to do with this.

Code:

        new query[256], authid[32]
        get_user_authid(id,authid,31)
        format( query, 255, "INSERT INTO users (steamid,exp,level,kills) VALUES('%s','0','1','0')", authid)


MaximusBrood 01-21-2007 16:43

Re: Register in the SQL if not already there?
 
Use:

Code:

INSERT INTO ... VALUES (...) ON DUPLICATE KEY UPDATE ...
http://dev.mysql.com/doc/refman/5.0/en/insert.html

blackops7799 01-21-2007 18:37

Re: Register in the SQL if not already there?
 
can you give me an example on how to use it?

JCobra 01-21-2007 18:48

Re: Register in the SQL if not already there?
 
Example from harbu's plugins (first thing to come to mind involving mysql and amxx :P)

Code:
format(query,255,"INSERT INTO jobs (JobID,JobName,Salary,Access) VALUES('%i','%s','%i','%s')",JobID,title,p_salary,JobRight)

"jobs" would be the table
"JobID" column,
"JobName" column,
"Salary" column
"Access" column
And then you just need to put %i for the amount of columns each database has, then define what you're putting in by listing them in the same order as you inserted them into the tables

MaximusBrood 01-21-2007 19:06

Re: Register in the SQL if not already there?
 
An example:

Code:

new query[256], authid[32]
get_user_authid(id,authid,31)

format( query, 255, "INSERT INTO users (steamid, exp, level, kills) VALUES('%s','0','1','0') ON DUPLICATE KEY UPDATE exp=exp+%d, level=%d, kills=kills+%d", authid, exp, level, kills)


MaximusBrood 01-22-2007 02:58

Re: Register in the SQL if not already there?
 
JCobra: Idiot

On my karma page:
Quote:

Copied what I put with different values. Thumbs down :(
You didn't have the whole ON DUPLICATE KEY clause.

dutchmeat 01-22-2007 03:58

Re: Register in the SQL if not already there?
 
Quote:

Originally Posted by MaximusBrood (Post 429976)
An example:

Code:

new query[256], authid[32]
get_user_authid(id,authid,31)
 
format( query, 255, "INSERT INTO users (steamid, exp, level, kills) VALUES('%s','0','1','0') ON DUPLICATE KEY UPDATE exp=exp+%d, level=%d, kills=kills+%d", authid, exp, level, kills)


isn't exp the current experience level ? if so, you are adding the current level to the database one...(on duplicate)

MaximusBrood 01-22-2007 04:14

Re: Register in the SQL if not already there?
 
I'm not aware of how the system is actually working, I was just giving an example :wink:


All times are GMT -4. The time now is 22:18.

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