Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
SQL Query to Delete Forum Spammers
Old 01-15-2009, 07:27 PM SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK, I'm getting sick and tired of the spammers that keep registering with my Conspiracy Forums. They compose of probably over 90% of the members list and that number almost doubles the number of posts! I've decided that I want to Hard Delete them from my MySQL Database.

The one thing that they have in common is that under the Biography field they all have the word "Man". So I figured the best way to remove these spammers is to create a query to move them to a certain usergroup I created (spammers) and then get the option to prune them all at once from that specific group, similar to what's going on here:
http://www.vbulletin.com/forum/showthread.php?p=1650640

The query I've got so far is:
PHP Code:
UPDATE user
SET usergroupid 
9
WHERE userfield1 LIKE 
'man' 
9 is the ID of the spammer group I created and userfield1 should be the name of the biography field, but I'm not completely sure (the DB shows a "field1" record for biography data, but it's under the table "userfield", so I don't know how to translate this into the WHERE portion of the query).

Thoughts?


Also, I know this won't stop new spammers from registering, but performing this bit of maintenance will clean up my forum greatly.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
 
Register now for full access!
Old 01-15-2009, 07:54 PM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
UPDATE user SET usergroupid  = 9 LEFT JOIN userfield  ON userfield.[useridcolumn] = user.[idcolumn] WHERE field1 LIKE 'man' ;
NOT TESTED just keyboard coding. Don't try it on live data
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-19-2009, 11:37 PM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Alright, I'll take your word on the query working for now .

Is there any way to effectively test it? If not then I could just back up my database and run it on the forum right away (closing it for a bit to make sure everything works well).
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-20-2009, 06:41 AM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
I would suggest installing MySql locally, mirroring the live DB and using HeidiSQL to test run the query.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-24-2009, 12:06 AM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Alright, I tested the above query and got this error:
PHP Code:
An error occurred while attempting to execute your query.
The following information was returned.
error number1064 
error desc
You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN userfield ON userfield.[useridcolumn] = user.[idcolumn] WHERE field1 ' at line 1 
So I tried it again spacing it out evenly:
PHP Code:
UPDATE user
SET usergroupid 
9
LEFT JOIN userfield
ON userfield
.[useridcolumn] = user.[idcolumn]
WHERE field1
LIKE 
'man'
And got this error:
PHP Code:
An error occurred while attempting to execute your queryThe following information was returned
error number1064 
error desc
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN userfield
ON userfield.[useridcolumn] = user.[idcolumn]
WHERE field1' 
at line 3 
Does this mean LEFT JOIN cannot be used? (Both the line numbers changed at the end, from line 1 to line 3, so I assume this is where the error is, but honestly though, I haven't the slightest idea what to do here.)
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-24-2009, 06:52 AM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Does this mean LEFT JOIN cannot be used?
Nope, it's because I have no idea what the column names actually are, so stuck a place holder in there....



... And then didn't make that clear in the post.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-24-2009, 11:45 AM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The useridcolumn is just called "userid" and then the column where all the man data is stored in "field1". These are both in the userfield table.

The new group I created (group 9) is in the usergroup table, and the column for the IDs is just called "usergroupid".

So would I change the last part to something like:
PHP Code:
ON userfield.[userid] = usergroup.[usergroupid]
WHERE userfield.[field1]
LIKE 'man'
Or do you need more info (or are the changes I made just plain wrong )?
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects

Last edited by jamestl2; 01-24-2009 at 11:47 AM..
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-24-2009, 12:00 PM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
this bit
= usergroup.[usergroupid] needs to be user.userid (use the column name of the ID column in the user list table.)

and remove the square brackets and it should be ok.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-24-2009, 12:09 PM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK, the userid column in the user table has the primary key set to it, so I don't think thats the column, however there is a "usergroupid" column showing which usergroup they belong to. So I assume here that's the table I replace the usergroup with (and remove the brackets)?

aka: user.usergroupid
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-24-2009, 12:59 PM Re: SQL Query to Delete Forum Spammers
Banned

Posts: 923
Name: Geoff Vader
Location: In my dreams
Trades: 0
Quote:
The one thing that they have in common is that under the Biography field they all have the word "Man".
That intrigues me. What are their IPs? I presume they are different, since you are a forum owner and would see if they were the same. Are they one person on lots of proxies? People very rarely have common identifiers like that - spam is generally chaotic. How come they all have the word "man" in this field and nonspammers don't? Are you sure... (1) that it's different spammers? {using the same jive could indicate the same gob} (2) that your method won't remove legitimate members without your stopping it in time?

I have thought of some ideas for how to change the spamming on, for example, this forum - you could query every new post for words like seo, social network, and then download the signature link, see what it's selling, maybe factor a few other things in (personally I would look for ungrammatical english) and after a bit of hard work and pattern-match engineering, i reckon you'd reduce spam by a big percentage.

I wonder if I'm a member of your forum! I doubt I'd use "man" in the field you mention, but you'll spot me easily because of the fact that the only thing I'm going to talk about there, if you're already in my spreadsheet, is how to boycott ------. (self-censored, keep politics out of programming).

It DOES sound worryingly like it cannot be lots of different people coincidentally dropping the same kind of footprint.

Here's my biography field for the current forum:
Quote:
Biography:Have signed a petition against calendars
whereas on other sites, I just don't fill it in at all.

However, I can't see how it's possible that the letters "man" are somehow exclusive to spammers, for that field?! I reckon you must have the same guy, managing to fool you. Hell I've seen people fool the forum owner (not spam, political activism, it's a different game) by being 15 different people across various proxies, and they actually speak in different languages as different members - it's a beautiful sight to see. But then i've seen much - i saw the hacking of a hamas forum into nonexistence from the point of view of the hacker! Not that I regret it. Hate is hate. Whoever breeds it.
witnesstheday is offline
Reply With Quote
View Public Profile
 
Old 01-24-2009, 01:11 PM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the usergroupid is the one you are updating (UPDATE user SET usergroupid = 9). The JOIN is to extract the users with id of xx who have an row that matches the WHERE clause

LEFT JOIN userfield.userid ON user.id WHERE ...
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-24-2009, 02:42 PM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
Quote:
Originally Posted by chrishirst View Post
the usergroupid is the one you are updating (UPDATE user SET usergroupid = 9). The JOIN is to extract the users with id of xx who have an row that matches the WHERE clause

LEFT JOIN userfield.userid ON user.id WHERE ...
OK, so that's not actually changing the data then, just reading the original id of the member then, I'll test it out.

Quote:
Originally Posted by witnesstheday View Post
That intrigues me. What are their IPs? I presume they are different, since you are a forum owner and would see if they were the same. Are they one person on lots of proxies? People very rarely have common identifiers like that - spam is generally chaotic. How come they all have the word "man" in this field and nonspammers don't? Are you sure... (1) that it's different spammers? {using the same jive could indicate the same gob} (2) that your method won't remove legitimate members without your stopping it in time?
They do all have different IP's. I'm guessing someone wrote a spam program and sent it out to many various forums, even WMT had a few spammers with the "Man" in the bio field.

I gave my members a fair warning though to make sure they don't have the word "Man" in that particular field:
http://www.conspiracy-forums.com/for...intenance.html

And it's been over a week so far, and honestly, my forum hasn't grown very much over the past year (an entirely seperate issue). Out of the entire fourm member list it has, I'd guess only about 25-30 members are legitimate (just sorting through their post counts will show you that roughly only the first page actually has people that have contributed).



Quote:
Originally Posted by witnesstheday View Post
I wonder if I'm a member of your forum! I doubt I'd use "man" in the field you mention, but you'll spot me easily because of the fact that the only thing I'm going to talk about there, if you're already in my spreadsheet, is how to boycott ------. (self-censored, keep politics out of programming).
I don't think I've seen you there, haven't seen any boycott threads.

I've already taken a look at the profiles of my regulars and I haven't seen any with the "Man" word in their biographies. So for right now, it shouldn't be an issue, and any legitimately new members should take a look at the thread I posted in the announcements section on my forum.

Quote:
Originally Posted by witnesstheday View Post
It DOES sound worryingly like it cannot be lots of different people coincidentally dropping the same kind of footprint.

However, I can't see how it's possible that the letters "man" are somehow exclusive to spammers, for that field?! I reckon you must have the same guy, managing to fool you. Hell I've seen people fool the forum owner (not spam, political activism, it's a different game) by being 15 different people across various proxies, and they actually speak in different languages as different members - it's a beautiful sight to see. But then i've seen much - i saw the hacking of a hamas forum into nonexistence from the point of view of the hacker! Not that I regret it. Hate is hate. Whoever breeds it.
Truthfully, the "man" field isn't the only thing the spammers have in common. If you look at the list I posted earlier, and find a spammer (like this one for example), the "Interests" and "Name" fields always have the spammer's username; even the "recent blog post" field has it, and that's suppose to contain a feed link.

But the "Man" value is a value that is consistent amongst ALL these spammers that have been registering each day. I probably have over a thousand of these spammers on my forum. I figured the easiest way to clean up my forum would be to take this path, given that writing something in SQL to match those variables too is far beyond my capabilities.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-24-2009, 09:40 PM Re: SQL Query to Delete Forum Spammers
Banned

Posts: 923
Name: Geoff Vader
Location: In my dreams
Trades: 0
it makes sense now - if it's some kind of software, then clearly that makes it eminently plausible! It's so sad, spam software. Software is... how can I put it into words. But how can people bastardize software like that? That's so wrong. So very wrong. I do pity people who make evil software - and I don't just mean MS word and Excel!!!
witnesstheday is offline
Reply With Quote
View Public Profile
 
Old 01-31-2009, 12:45 AM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
OK, I tried all the following queries (because I'm not sure what exactly is correct):

PHP Code:
UPDATE user
SET usergroupid 
9
LEFT JOIN userfield
ON userfield
.[useridcolumn] = user.userid
WHERE field1
LIKE 
'man'
PHP Code:
UPDATE user
SET usergroupid 
9
LEFT JOIN userfield
.userid
ON user
.id
WHERE field1
LIKE 
'man'
PHP Code:
UPDATE user
SET usergroupid 
9
LEFT JOIN userfield
.userid
ON user
.userid
WHERE field1
LIKE 
'man'
...and they all return errors. Chris, did I misread one of your posts on what the correct query to use is?

Maybe it'd be easier to understand if just the entire query is posted to try out...
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-31-2009, 09:43 AM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the last one looks to be the correct syntax, what is the error this one throws?
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-31-2009, 10:51 AM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
The whole error it gives is:
PHP Code:
An error occurred while attempting to execute your queryThe following information was returned
error number1064 
error desc
You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN userfield.userid
ON user.userid
WHERE field1
LIKE '
man'' at line 3 
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-31-2009, 12:53 PM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Ok

I gave in and threw some temporary tables and data up

Code:
UPDATE user as u
LEFT JOIN userfield as uf ON uf.userid = u.id
SET u.usergroupid = 9
WHERE instr(uf.field1,"man");
works Ok on my temp setup.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 01-31-2009, 07:25 PM Re: SQL Query to Delete Forum Spammers
jamestl2's Avatar
No scale-itch here...

Latest Blog Post:
Wordpress Relative URLs Plugin
Posts: 2,389
Name: <member type="brilliant" alt="foolish">James Lewitzke</member>
Location: / public_html / Universe / Virgo_Supercluster / Local_Group / Milky_Way / Orion_Arm / Solar_System / Earth / North_America / USA / Wisconsin
Trades: 0
New Error:
PHP Code:
An error occurred while attempting to execute your queryThe following information was returned
error number1054 
error desc
Unknown column 'u.id' in 'on clause' 
I really wish I could understand SQL better . I'm not exactly sure what those new variables are.
__________________
Engipress -
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
for Wordpress Projects
jamestl2 is offline
Reply With Quote
View Public Profile Visit jamestl2's homepage!
 
Old 01-31-2009, 07:55 PM Re: SQL Query to Delete Forum Spammers
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
error desc: Unknown column 'u.id' in 'on clause'
u.id is not a variable...
it's the field "id" from the table that is aliased by "u" (user, in this case).
Look:
Code:
UPDATE --Ok, so we are going to update a table
  user as u  --Here, you declare that the table "user" will be referenced as "u" later. It's an alias. The field that we update is in that table too.
LEFT JOIN userfield as uf --Same thing here, userField is declared with the "uf" alias.
  ON uf.userid = u.id  --And you tell the DB that the mapping between the 2 tables should be done between the field user.id (u.id) and userField.userid (uf.userid)
SET u.usergroupid = 9  --And here, you tell the db that for each rows that match the criterias, the field "userGroupId" in the table "user" must be changed to the value 9
WHERE instr(uf.field1,"man"); --but only for rows in the table "userField" that have the string "man" into the field "userField.field1"
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 01-31-2009, 08:19 PM Re: SQL Query to Delete Forum Spammers
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
error desc: Unknown column 'u.id' in 'on clause'
And what that error is telling you, is that there is no column called "id" in the table called "user".
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to SQL Query to Delete Forum Spammers

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.73878 seconds with 12 queries