MyBB Community Forums

Full Version: Not updating lastpost
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I got a little question, what's wrong with this PHP code that is not updating the forum lastpost?

if ($form['forum_fid'] != 0)
 {
 $user=$mybb->user['username'];
 if ($user == '')
 {
 $user="Guest";
 }
 $uid=$mybb->user['uid'];
 $insert_array = array(
 "fid" => intval($form['forum_fid']),
 "subject" => $oggetto,
 "icon" => 0,
 "uid" => intval($uid),
 "username" =>  $user,
 "dateline" => time(),
 "lastpost" => time(),
 "closed" => "",
 "visible" => 1,
 );
 $db->insert_query("threads", $insert_array);
 $newtid = $db->insert_id();
 $insert_post = array(
 "tid" => intval($newtid),
 "subject" => $oggetto,
 "fid" => intval($form[forum_fid]),
 "uid" => intval($uid),
 "username" =>  $user,
 "dateline" => time(),
 "message" => $bbmessage,
 "visible" => 1,
 );
 $db->insert_query("posts", $insert_post);
 //UPDATE POSTCOUNT
 $update_posts = array(
 "postnum" => $mybb->user['postnum']+1,
 );
 $db->update_query("users", $update_posts, "uid='$uid'");
 //UPDATE STATS
 update_thread_counters($newtid, array("replies" => "+1"));
 update_forum_counters($form['forum_fid'], array("threads" => "+1", "posts" => "+1"));
 update_forum_lastpost($form['forum_fid']);
 $db->update_query("forums", $updated_forum, "fid='{$fid}'");
 $cache->update_stats();
 }
Why don't you use the datahandler?

For example:
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("insert");
$posthandler->action = "thread";

$new_thread = array (
	"fid" => intval($form['forum_fid']),
	"subject" => $oggetto,
	"uid" => intval($uid),
	"username" => $user,
	"message" => $bbmessage,
);

$posthandler->set_data($new_thread);

$valid_thread = $posthandler->validate_thread();

if (!$valid_thread)
{
	die($posthandler->get_friendly_errors());
}

$thread_info = $posthandler->insert_thread();

$thread_info:
https://github.com/mybb/mybb/blob/fda43f...1725-L1729
(2016-01-27, 01:49 AM)nth Wrote: [ -> ]Why don't you use the datahandler?

For example:
require_once MYBB_ROOT."inc/datahandlers/post.php";
$posthandler = new PostDataHandler("insert");
$posthandler->action = "thread";

$new_thread = array (
 "fid" => intval($form['forum_fid']),
 "subject" => $oggetto,
 "uid" => intval($uid),
 "username" => $user,
 "message" => $bbmessage,
);

$posthandler->set_data($new_thread);

$valid_thread = $posthandler->validate_thread();

if (!$valid_thread)
{
 die($posthandler->get_friendly_errors());
}

$thread_info = $posthandler->insert_thread();

$thread_info:
https://github.com/mybb/mybb/blob/fda43f...1725-L1729

Hey thanks, this worked fine, but there's a small problem, whenever there is an apostrophe, a trailing slash gets shown with it and as far as I know MyBB deletes every double slash by its own, so how come?
It should be fine.

Check that your code isn't escaping it before you insert it.
(2016-01-27, 03:48 PM)nth Wrote: [ -> ]It should be fine.

Check that your code isn't escaping it before you insert it.
Ye, I didn't rly check my code that good. Just checked out with more attention and it was escaping, got it working now. Thanks for your help Wink