I tried a auto-comment bot for wordpress(in my website) and coded it. My plan is that I write names in names.txt file and sample comments in comments.txt file(a name or comment per line) and it will add a random comment with a random name into Wordpress's database in wp_comments table. I also planned to increase comment_count value in wp_posts table, however my code is not working. Here is the code:


include "wp-config.php";

$asama1=@mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("<h1>Something was wrong.</h1>");
$asama2=@mysql_select_db(DB_NAME,$asama1) or die("<h1>Database could not be found.</h1>");

$kactane=(integer) $x;


// ------------------- random names and comments adding to db is starting.------------

$yorumla=@mysql_query("INSERT INTO wp_comments(comment_post_ID,comment_author,comment_content,comment_approved,comment_parent,user_id) VALUES($id,$ekleisim,$ekleyorum,'1','0','0')");
$yorumsayal=@mysql_query("SELECT comment_count FROM wp_posts WHERE id=$id");
$sayiart=@mysql_query("INSERT INTO wp_posts(comment_count) VALUES($yorumsayal)");
echo $yorumsayi.". yorum eklendi.</br>";
// -------------------end of random names and comments adding to db.--------------
serrion9 commented: Hey, I've just received a free Minecraft Giftcode! You can get one too! >> minecraftcodes.me << +0

Recommended Answers

All 3 Replies

Just use a mysql database to store the names, then you can connect to the database, and select a random name.. here is an example of a random i made for a simple video game lotery

// Echo random

$username="db_user"; //enter your database username
$password="password"; //enter your db password
$database="db_name"; //enter the name of your database

@mysql_select_db($database) or die( "Unable to select database"); 
$query=	"SELECT * FROM pins WHERE used > 0 ORDER BY RAND() LIMIT 1"; 


while ($i < $num) {


It selects a random row from a mysql database that has the column value greater that 0. Then it echos it out...

Go check it out - http://ggdesigning.com/test_random.php

commented: thank you for your answer:) +0

thank you for answer. I haven't used mysql_result() function but I'm going to try it. I thought that using txt files are easy to use and edit, besides couldn't I use txt files as arrays using file() function?

You could but with a mysql database, you can setup an easy access form to add stuff, delete stuff, edit stuff, ect

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.