2006-01-06, 09:45 PM
I'm using the following function to create threads on the forum automatically. The problem is that the line "$tid = $db->insert_id();" doesn't return the correct tid. For whatever reason it always returns a number around 10-14 instead of the actual thread id. As a result when I create the post that goes in the thread it has the wrong tid as well. Does anyone know how to fix this? (btw the I got the code from dennistt's report to forum plugin and it seems to work fine there).
Thank you for any advice!
function videos_create_thread()
{
global $mybb, $db, $post, $thread, $pid, $forum, $templates, $cache;
$message = "message";
$newthread = array(
"fid" => 36,
"subject" => addslashes("Testing Video Library Thread Creation"),
"icon" => -1,
"uid" => $mybb->user['uid'],
"username" => addslashes(htmlspecialchars_uni($mybb->user['username'])),
"dateline" => time(),
"lastpost" => time(),
"lastposter" => addslashes(htmlspecialchars_uni($mybb->user['username'])),
"views" => 0,
"replies" => 0,
"visible" => 1
);
$db->insert_query("mybb_threads", $newthread);
$tid = $db->insert_id(); //PROBLEM LINE
print "<br> tid: $tid <br>";
$newpost = array(
"tid" => $tid,
"fid" => 36,
"subject" => addslashes("Testing Video Library Thread Creation"),
"icon" => -1,
"uid" => $mybb->user['uid'],
"username" => addslashes(htmlspecialchars_uni($mybb->user['username'])),
"dateline" => time(),
"message" => addslashes($message),
"ipaddress" => getip(),
"includesig" => "no",
"smilieoff" => "no",
"visible" => 1
);
print_r($newpost);
$db->insert_query("mybb_posts", $newpost);
$pid = $db->insert_id();
print "<br> pid: $pid";
$firstpostup = array("firstpost" => $pid);
$db->update_query("mybb_threads", $firstpostup, "tid='$tid'");
$parents = explode(",", $forum['parentlist']);
foreach($parents as $parentfid)
{
updateforumcount($parentfid);
}
$cache->updatestats();
updatethreadcount($tid);
}
Thank you for any advice!