MyBB Community Forums

Full Version: Create Thread from PHP Script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I run a myBB forum. http://orcahub.com/forum/

I also do a lot of work in PHP.

I want to make a new thread in a specified category from my admin account on the forum, with specific title and contents from my php script.

Here is what I used to use, but this will generate problems over time as it isn't completely right

Here is the method I coded myself


function makethread($subject, $thread) {

$host="***"; // Host name
$username="***"; // Mysql username
$password="***"; // Mysql password
$db_name="***"; // Database name


mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$ridtid = rand(111111,999999);

$time = time();
$q1 = "INSERT into mybb_posts (tid, fid, subject, icon, uid, username, message, visible) VALUES('$ridtid', '7', '$subject', '6', '1', 'Nick', '$thread', '1')";
$q2 = "INSERT into mybb_threads (tid, fid, subject, icon, uid, username, dateline, lastpost, lastposter, visible) VALUES('$ridtid', '7', '$subject', '6', '1', 'Nick', '$time', '$time', 'Nick', '1')";
$q3 = "UPDATE mybb_forums SET lastposttid='$ridtid' WHERE fid='7'";
$q4 = "UPDATE mybb_forums SET lastpost='$time' WHERE fid='7'";
mysql_query($q1);
mysql_query($q2);
mysql_query($q3);
mysql_query($q4);

 }



What is the official way to do it?
I join the request, i have the same problem and i need do query, which will send message from php.
Thank you for the support, hopefully we can get some resolution soon.
Still requesting an update on this.
Umm.. there's no official way to do it because this isn't an official feature.

If I were to attempt something like this, I would check out newthread.php.
You would need to make sure you have the following:

define("IN_MYBB", 1);
- this code says "hey, I'm an official MyBB script" even though it's not, but it allows you to use MyBB's databse connection.

require_once "./global.php";
- this code includes the database connection.

if($mybb->user['uid'])
- this checks to see if the user is logged in. If you don't want this, it's not required.

<form method="post" enctype="multipart/form-data" action="newthread.php?fid=1&amp;processed=1">
<input type="hidden" name="my_post_key" value="1903c2f33dcaeedf69e952693f387691">
<input type="hidden" name="action" value="do_newthread">
<input type="hidden" name="posthash" value="103d98dd51342a065b7fe55752481be5" id="posthash">
- make sure you include the above inputs in your form. If you notice the action tag includes a FID which is a Forum ID. You can pick which forum you would like to have the script place the post in by changing the FID


There's quite a few comments in the newthread.php file that you can check out. 

I would say just to recreate newthread.php.. but strip it down. If you come up with something, and it doesn't work.. create a new post about the errors you're receiving and PM me the link and I'll check it out. 

Good luck!
(2015-10-08, 03:54 AM)sparkks Wrote: [ -> ]Umm.. there's no official way to do it because this isn't an official feature.

If I were to attempt something like this, I would check out newthread.php.
You would need to make sure you have the following:

define("IN_MYBB", 1);
- this code says "hey, I'm an official MyBB script" even though it's not, but it allows you to use MyBB's databse connection.

require_once "./global.php";
- this code includes the database connection.

if($mybb->user['uid'])
- this checks to see if the user is logged in. If you don't want this, it's not required.

<form method="post" enctype="multipart/form-data" action="newthread.php?fid=1&amp;processed=1">
<input type="hidden" name="my_post_key" value="1903c2f33dcaeedf69e952693f387691">
<input type="hidden" name="action" value="do_newthread">
<input type="hidden" name="posthash" value="103d98dd51342a065b7fe55752481be5" id="posthash">
- make sure you include the above inputs in your form. If you notice the action tag includes a FID which is a Forum ID. You can pick which forum you would like to have the script place the post in by changing the FID


There's quite a few comments in the newthread.php file that you can check out. 

I would say just to recreate newthread.php.. but strip it down. If you come up with something, and it doesn't work.. create a new post about the errors you're receiving and PM me the link and I'll check it out. 

Good luck!

If you can give me a simple script which does this.

Accepts $subject and $contents and then creates thread I will give you $20.

The newthread.php is a spider web, there is no way I am going to be parse that.
Go ahead and send me a PM when you get a chance. I could work on this.
Sent you a PM.
Still looking for this to be done.