Topic: [Solved] Changing the author of a thread through the database
I assume it can be done.
Anyone could give me some leads as where to look?
Thanks!
You are not logged in. Please login or register.
PunBB Forums → PunBB 1.2 troubleshooting → [Solved] Changing the author of a thread through the database
I assume it can be done.
Anyone could give me some leads as where to look?
Thanks!
It's easily done using SQL...
ALTER TABLE posts SET user_id=X WHERE id=Y;
replace X by the new user id and Y by the post id.
This is not something very dangerous or anything, but be careful playing around with your database if you are not comfortable doing it. Better make a backup before if you are not sure of what you're doing.
That would be an update statement, not an alter table statement
OMG... i just forgot the ABC of SQL... sorry {embarrassed mode}
thanks smartys. this is particularly funny if one reads what i wrote together with that fine piece of 'personal' SQL.
vanslide, it is:
UPDATE TABLE posts SET user_id=X WHERE id=Y;
update table won't work on MySQL I believe, you need just update
eheheh... I wonder if vanslyde or any other person will actually trust me with any tips after this.
It's the mnemonic i have in my head... "update table set...where" sorry...
ok.. so... let's see if the 3rd is the final one:
UPDATE posts SET user_id=X WHERE id=Y;
mmm, I should probably have mentioned this, but user_id doesn't exist: poster_id is what you're looking for
lol naaa I'm trusting you guys. I was at the movies so didn't tried the first few queries
But still, the last one (with smarty's comment about poster_id) didn't work. I ran the following;
UPDATE posts SET poster_id=83 WHERE id=591;
and got the following results;
Instead of having the username of poster 83 next to post 591, I get the original username BUT it now has the poster id 83...
Oh, you want to change the author of a topic?
update topics set poster="name" where id=topic_id
where name is the name you want and topic_id is the ID of the topic.
UPDATE posts SET poster_id=X, poster="name" WHERE id=Y;
Variable use is the same (name is the name you want, X is the user id, Y is the id of the post
It works, thanks guys!
edit: so you have to run the 2 ^^ queries.
first one for the authors' names appearing in the list of topics and 2nd one for the name displayed in the first post of said topic
okay, so let's say the thread/topic contains a single post and that I ran the 2 queries in order to change the author's name displayed in the list of topic, and in the actual 1rst (and last) post of said thread.
Now, is there a 3rd query I have to run in order to make the new username appear in the Last post by column displayed in the list of topics? Otherwise the name of the original poster would still be displayed.
Thanks again!
Make the first query
update topics set poster="name", last_poster="name" where id=topic_id
and run update_forum
and run update_forum
I'm not familiar with this function, is it a mysql query? because I get a syntax error when running it there. Now I understand that it has something to do with include/functions.php but how (or where) can I run it?
edit: or do I simply have to navigate to this php page?
It's a PHP function.
It's a PHP function.
which is included in functions.php so I just have to refresh my browser and the function will be automatically called?
No, it needs to be called within your file: include/functions.php simply defines what the function is and does, it doesn't execute it.
I copied said function to a new php file, and browsed to it. But I don't see any output whatsoever... I get a blank page. (obviously, first time calling a function here..).
OK.
You just want to add the following code
update_forum(number);
where number is the ID of the forum where the topic is. This assumes you've included include/functions.php somehow (most likely using include/common.php)
this is not what you meant, right?
That is the function you have to call indeed. Just post in the forum you changed and it should be done.
That's what I meant without the function update_forum ($forum_id) { ... } stuff (that's already defined in include/functions.php. The way to use a function is exactly what you did in your last line.
That's what I meant without the function update_forum ($forum_id) { ... } stuff (that's already defined in include/functions.php. The way to use a function is exactly what you did in your last line.
well if I only have to browse to this php file:
<?php
define('PUN_ROOT', './');
require PUN_ROOT.'include/functions.php';
update_forum(7);
?>
I'm getting the error
Fatal error: Call to a member function query() on a non-object in C:\wamp\www\forums\include\functions.php on line 364
__ __ __
line 364 of function.php is
$result = $db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $db->error());
list($num_topics, $num_posts) = $db->fetch_row($result);
You have to include common.php, not functions.php
You have to include common.php, not functions.php
Then I'd get a blank page with no output whatsoever, is that normal?
Yes, nothing there would generate any output.
PunBB Forums → PunBB 1.2 troubleshooting → [Solved] Changing the author of a thread through the database
Powered by PunBB, supported by Informer Technologies, Inc.