Delete bogus users
-
I’ve got a problem with the number of fake users on my site.
There are around 3,234 users on the site, with around 2,990 fake.
I’ve written a script in php.
This script accurately echos the fake users, then puts them into an array called $dupe_ID.
I then do a foreach loop using the DELETE FROM command.
If it returns true, I ask it to iterate by one.
On execution: It does the correct number of iterations, but nothing is deleted from the database, does anyone know why?
Thanks.
<?php $servername = "localhost"; $dbname = "michaelt****3"; $username = "michaelt***3"; $password = "P******"; // Create connection $link = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$link) { die("Connection failed: " . mysqli_connect_error()); } echo "Connected successfully <br>"; //If form submitted if ($_GET["form"] == "true") { echo '<H1>FORM SUBMITTED</H1>'; // select all users $query = "SELECT wp_users.ID FROM wp_users,wp_comments GROUP BY wp_users.ID ORDER BY wp_users.display_name asc"; $result = $link->query($query); while($row = mysqli_fetch_array($result)) { $all_names[]=$row["ID"]; } $query = "SELECT wp_users.ID FROM wp_users,wp_comments WHERE INSTR (wp_users.display_name, wp_comments.comment_author) > 0 GROUP BY wp_users.ID ORDER BY wp_users.display_name asc"; //execute the query. $result = $link->query($query); //display information: while($row = mysqli_fetch_array($result)) { $names[]=$row["ID"]; } $dupe_ID = array_diff($all_names,$names); $i=0; // LOOP THE COMMAND foreach ($dupe_ID as $value) { // DELETE THE USERS $query = "DELETE FROM wp_users WHERE ID = $value"; if (mysqli_query($link, $query)) { $i++; } else { echo "Error deleting records: " . mysqli_error($link); } } echo $i . 'Names deleted'; } else { // select all users $query = "SELECT wp_users.display_name FROM wp_users,wp_comments GROUP BY wp_users.ID ORDER BY wp_users.display_name asc"; $result = $link->query($query); while($row = mysqli_fetch_array($result)) { $all_names[]=$row["display_name"]; } $query = "SELECT wp_users.display_name FROM wp_users,wp_comments WHERE INSTR (wp_users.display_name, wp_comments.comment_author) > 0 GROUP BY wp_users.ID ORDER BY wp_users.display_name asc"; //execute the query. $result = $link->query($query); //display information: while($row = mysqli_fetch_array($result)) { $names[]=$row["display_name"]; } $dupe_names = array_diff($all_names,$names); $i=1; // print out the bogus names foreach ($dupe_names as $value) { echo $i.')'. $value .'<br>'; $i++; } echo '<p><h3>To delete these names click here </h3></p>'; echo '<form method="GET" target="bogus_users.php" ><input type=submit label="Destroy these entries" value="Submit"><input type="hidden" name="form" value="true"></form>'; } ?>
- The topic ‘Delete bogus users’ is closed to new replies.