1 (edited by Vanslyde 2007-07-11 14:27)

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!

Re: [Solved] Changing the author of a thread through the database

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.

Re: [Solved] Changing the author of a thread through the database

That would be an update statement, not an alter table statement wink

Re: [Solved] Changing the author of a thread through the database

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;

Re: [Solved] Changing the author of a thread through the database

update table won't work on MySQL I believe, you need just update wink

Re: [Solved] Changing the author of a thread through the database

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;

Re: [Solved] Changing the author of a thread through the database

mmm, I should probably have mentioned this, but user_id doesn't exist: poster_id is what you're looking for tongue

8 (edited by Vanslyde 2007-07-08 02:40)

Re: [Solved] Changing the author of a thread through the database

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...

Re: [Solved] Changing the author of a thread through the database

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

10 (edited by Vanslyde 2007-07-09 04:37)

Re: [Solved] Changing the author of a thread through the database

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

Re: [Solved] Changing the author of a thread through the database

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!

Re: [Solved] Changing the author of a thread through the database

Make the first query

update topics set poster="name", last_poster="name" where id=topic_id

and run update_forum

13 (edited by Vanslyde 2007-07-10 00:36)

Re: [Solved] Changing the author of a thread through the database

Smartys wrote:

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?

Re: [Solved] Changing the author of a thread through the database

It's a PHP function.

Re: [Solved] Changing the author of a thread through the database

Smartys wrote:

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?

Re: [Solved] Changing the author of a thread through the database

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.

Re: [Solved] Changing the author of a thread through the database

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..).

Re: [Solved] Changing the author of a thread through the database

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)

Re: [Solved] Changing the author of a thread through the database

this is not what you meant, right?  hmm

http://i119.photobucket.com/albums/o144/indiequebec/updateforum.gif

Re: [Solved] Changing the author of a thread through the database

That is the function you have to call indeed. Just post in the forum you changed and it should be done.

Re: [Solved] Changing the author of a thread through the database

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.

Re: [Solved] Changing the author of a thread through the database

Smartys wrote:

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);

Re: [Solved] Changing the author of a thread through the database

You have to include common.php, not functions.php

Re: [Solved] Changing the author of a thread through the database

elbekko wrote:

You have to include common.php, not functions.php

Then I'd get a blank page with no output whatsoever, is that normal?

Re: [Solved] Changing the author of a thread through the database

Yes, nothing there would generate any output.