SELECT * FROM phpbb_posts WHERE poster_id = -1 AND post_username = '<name>'
The query correctly shows all posts where the poster_id is -1 with matching username.
What I need to do now, is change the poster_id to the original user_id number of 10 (of which the deleted account has been recreated and the user_id changed). How do I do that?
I'm also aware that the same would need doing for topic_poster. The only thing I'm unsure of is whether the post count would need updating as well and if the SQL would need doing the same time the above query is done?
When I think of it, this could be an extremely handy MOD for anyone unfortunate to accidentally delete a members account, especially one originally consisting of many, many posts. I am aware that the alternative is to think of it as bad luck and to create another account but it can't be that difficult to "undelete"... is it?
Note: My assistance required is for phpbb2.
EDIT: I've come across the following but it doesn't work when run because it keeps returning a parse error. I've tried to fathom it out but with no joy.
Code: Select all
<?php
$host=”localhost”;
$user=”********”;
$password=”********”;
$dbname=”phpb2”;
$link=mysql_connect ($host, $user, $password);
$nr_posts = 0;
$query = “SELECT * FROM phpbb_posts WHERE poster_id = -1 AND post_username = '<someone>'";
$result=mysql_db_query($dbname, $query, $link);
while ($Row = mysql_fetch_array($result))
{
$queryz = “SELECT * FROM phpbb_topics WHERE topic_first_post_id = $Row[post_id] AND topic_poster = -1";
$resultz=mysql_db_query ($dbname, $queryz, $link);
$num_rows = mysql_num_rows($resultz);
if ($num_rows)
{
print $Row[post_id] . ” - “;
$tRow = mysql_fetch_array($resultz);
$queryz = “UPDATE phpbb_topics SET topic_poster=10 WHERE topic_id = $tRow[topic_id]” ;
$resultz=mysql_db_query ($dbname, $queryz, $link);
}
$queryz = “UPDATE phpbb_posts SET poster_id=10 WHERE post_id = $Row[post_id]” ;
$resultz=mysql_db_query ($dbname, $queryz, $link);
$nr_posts = $nr_posts + 1;
}
$queryz = “UPDATE phpbb_users SET user_posts = $nr_posts WHERE user_id = 10" ;
$resultz=mysql_db_query ($dbname, $queryz, $link);
mysql_close ($link);
?>