Raised This Month: $ Target: $400
 0% 

Register in the SQL if not already there?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blackops7799
Senior Member
Join Date: May 2006
Old 01-21-2007 , 13:45   Register in the SQL if not already there?
Reply With Quote #1

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)
blackops7799 is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 01-21-2007 , 16:43   Re: Register in the SQL if not already there?
Reply With Quote #2

Use:

Code:
INSERT INTO ... VALUES (...) ON DUPLICATE KEY UPDATE ...
http://dev.mysql.com/doc/refman/5.0/en/insert.html
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
blackops7799
Senior Member
Join Date: May 2006
Old 01-21-2007 , 18:37   Re: Register in the SQL if not already there?
Reply With Quote #3

can you give me an example on how to use it?
blackops7799 is offline
JCobra
Senior Member
Join Date: Mar 2006
Location: Canada
Old 01-21-2007 , 18:48   Re: Register in the SQL if not already there?
Reply With Quote #4

Example from harbu's plugins (first thing to come to mind involving mysql and amxx )

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
__________________
User has abandoned this account.
JCobra is offline
Send a message via AIM to JCobra
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 01-21-2007 , 19:06   Re: Register in the SQL if not already there?
Reply With Quote #5

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)
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 01-22-2007 , 02:58   Re: Register in the SQL if not already there?
Reply With Quote #6

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.
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
dutchmeat
Senior Member
Join Date: Sep 2006
Old 01-22-2007 , 03:58   Re: Register in the SQL if not already there?
Reply With Quote #7

Quote:
Originally Posted by MaximusBrood View Post
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)
__________________
before you criticize someone, you should walk a mile in their shoes. that way, when you criticize them, you're a mile away and you have their shoes.
dutchmeat is offline
MaximusBrood
Veteran Member
Join Date: Sep 2005
Location: The Netherlands
Old 01-22-2007 , 04:14   Re: Register in the SQL if not already there?
Reply With Quote #8

I'm not aware of how the system is actually working, I was just giving an example
__________________
Released six formerly private plugins. Not active here since ages.
MaximusBrood is offline
Reply



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 22:18.


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