View Full Version : code to post a thread

11 Dec 2009, 00:06
im building a mod and one of the features i need is for it to automatically make threads but i cant seem to get it to work this the code ive got atm ive taken it from the newthread.php file but it doesnt work or give me any information as to why.

$result = $db->query_read_slave(
"SELECT * FROM " . TABLE_PREFIX . "mods WHERE id = " . intval($_REQUEST['id']));

$mod = $db->fetch_array($result);

// set arrays
$foruminfo = array();
$newpost = array();
$errors = array();
require_once(DIR . '/includes/functions_newpost.php');
$foruminfo['forumid'] = 2;
$newpost['message'] = ' . ']Link to mod (http://localhost:8888/forum/mods.php?do=view&id=' . $mod['id')
' . $mod['description'];
$newpost['title'] = $mod['title'];
$newpost['username'] = $mod['username'];
$newpost['poststarttime'] = time();
$newpost['rating'] = 0;
// trick it
$tmp_id = $vbulletin->userinfo['userid'];
$vbulletin->userinfo['userid'] = $mod['userid'];
build_new_post('thread', $foruminfo, array(), array(), $newpost, $errors);
$vbulletin->userinfo['userid'] = $tmp_id;

anyone got any ideas? :)

13 Dec 2009, 03:50
ok it sort of works now . now atleast something happens but it returns
That username is already in use or does not meet the administrator's standards. If you are racken and you have forgotten your password, click here.

in the error parameter which doesnt make any sense surly that would be a registration error?

13 Dec 2009, 05:04
I don't know exactly what you are trying to do, but I am guessing the problem lies where you are reassigning the userid. That is the area I would be looking into.

And what does this mean - "If you are racken and" - racken?

13 Dec 2009, 13:18
because the thread im trying to create i want to be posted under a different user so that user can edit it so if i run that script logged into an account renlok i was trying to make a thread posted by racken

13 Dec 2009, 16:19
I understand that. What I'm saying is that it seems to me that that is the area that has problems so that is the area I would focus on. Try posting the thread without switching the userid - does it work then? How about manually putting in a userid - like '5' (use a valid userid) - does it work then? Typical debug stuff to do.

14 Dec 2009, 14:14
finally got it to work :D

14 Dec 2009, 14:23
Do you want a new thread or a new post? It looks to me like you are using a new post method for a new thread.

You should be using the datamanager built in to vbulletin to post threads.

My suggestion would be to go and download my Welcome Thread mod and look how I did it.

14 Dec 2009, 15:56
finally got it to work :D
Out of curiosity, what was the problem?

14 Dec 2009, 18:21
it was trying to set the userid as 0 so it was trying to make the post as a guest which was why i was getting that error message. but it works now apart from it times out after making the post which is annoying but i dont mind.