PDA

View Full Version : Insert Thread into database.


Killa878
07-02-2011, 05:52 PM
Hello all,

im trying to create a PHP Function that will add a thread to the forums.
This is what i got must its not working:

private function MakeThread( $ForumId, $Title, $Content )
{
mysql_query( "INSERT INTO `thread` (`threadid`,`title`,`prefixid`,`firstpostid`,`last postid`,`lastpost`,`forumid`,`pollid`,`open`,`repl ycount`,`hiddencount`,`deletedcount`,`postusername `,`postuserid`,`lastposter`,`dateline`,`lastedit`, `views`,`iconid`,`notes`,`visible`,`sticky`,`voten um`,`votetotal`,`attach`,`similar`,`taglist`,`vbse o_linkbacks_no`,`lastposterid`,`keywords`,`wrdate` ) VALUES (NULL, '". mysql_real_escape_string($Title) ."', '', '0', '0', '". $ForumId ."', '0', '0', '0', '0', '0', '". $this->UserData['username'] ."', '". $this->UserData['userid'] ."', '". $this->UserData['username'] ."', '". SCRIPT_TIME ."', '0', '0', '', '0', '', '1', '0', '0', '0', '0', '0', '0', '". $this->UserData['userid'] ."', '0', '0')" ) or die( "Q1: " . mysql_error( ) );

// Get the inserted thread ID
$ThreadID = mysql_insert_id( );

mysql_query( "INSERT INTO 'post` (`postid`,`threadid`,`parentid`,`username`,`userid `,`title`,`dateline`,`lastedit`,`pagetext`,`allows milie`,`showsignature`,`ipaddress`,`iconid`,`visib le`,`attach`,`infraction`,`reportthreadid`,`htmlst ate`) VALUES (NULL, '". $ThreadID ."', '0', '". $this->UserData['username'] ."', '". $this->UserData['userid'] ."', '', '". SCRIPT_TIME ."', '', '" . $Content . "', '0', '0', '". $this->UserIP ."', '0', '1', '0', '0', '0', 'on_nl2br')" ) or die( "Q2: " . mysql_error( ) );

$PostID = mysql_insert_id( );

mysql_query( "UPDATE `thread` SET `firstpostid` = " . $PostID . ", `lastpostid` = " . $PostID . " WHERE `threadid` = " . $ThreadID . " LIMIT 1" );
}

All the vars such as UserData and Username is ok. As they are stored within the class.

At this point no thread is being made.

Thanks

kh99
07-02-2011, 06:43 PM
I'm not sure, but if I'm counting right it looks like maybe you're not setting 'visible' to 1 (it looks like you're setting 'sticky' to 1 so probably something's off by one).

Killa878
07-02-2011, 07:05 PM
I'm not sure, but if I'm counting right it looks like maybe you're not setting 'visible' to 1 (it looks like you're setting 'sticky' to 1 so probably something's off by one).

Hmm. i checked into the database and there wasnt any new inserted rows with anything that i created.

I counted and it looks correct.

kh99
07-02-2011, 07:48 PM
I count 31 columns and 30 values, again unless I'm screwing up somehow. I pasted it into phpmyadmin, changed the vars to constants, and I got a "value count doesn't match" or something like that (the first query, I mean).

But I don't know why you wouldn't see any error messages. Here's a stupid question - are you sure that's even getting called?

Killa878
07-02-2011, 07:51 PM
I count 31 columns and 30 values, again unless I'm screwing up somehow. I pasted it into phpmyadmin, changed the vars to constants, and I got a "value count doesn't match" or something like that (the first query, I mean).

But I don't know why you wouldn't see any error messages. Here's a stupid question - are you sure that's even getting called?

Yeah its getting called :D
i just did a re-count and got 31 columns and 31 values.

Im stumped on this.

BirdOPrey5
07-02-2011, 11:08 PM
Check out my "New Thread on User Banning (https://vborg.vbsupport.ru/showthread.php?t=257041)" mod- it makes a new thread.

Here's a copy of the code to make a new thread... I got it off a tutorial somewhere around here that was for 3.x but the code is the same.



$bop5onban_fid = 2; //Forum ID for new thread

//Set new thread details...

$banthread =& datamanager_init('Thread_FirstPost', $vbulletin, ERRTYPE_ARRAY, 'threadpost');
$foruminfo = fetch_foruminfo($bop5onban_fid);
$threadinfo = array();
$forumid = $bop5onban_fid;

//Set some thread/post settings
$bop5postip = "127.0.0.1";
$bop5allowsmilie = '1';
$bop5visible = 1;

$banthread->set_info('forum', $foruminfo);
$banthread->set_info('thread', $threadinfo);
$banthread->setr('forumid', $forumid);
$banthread->setr('userid', $bop5onban_uid);
$banthread->setr('pagetext', $bop5onban_text);
$banthread->setr('title', $bop5onban_title);
$banthread->set('iconid', $vbulletin->options['bop5onban_icon']);
$banthread->set('allowsmilie', $bop5allowsmilie);
$banthread->set('visible', $bop5visible);
$banthread->set('ipaddress', $bop5postip);
$banthread->set('showsignature', $vbulletin->options['bop5onban_sig']);

$banthread->pre_save();
if(count($banthread->errors) < 1)
{
$threadid = $banthread->save();
unset($banthread);
build_thread_counters($banthread);
}
else
{
print "Error making new thread! " . $banthread->errors[0] . $banthread->errors[1] . $banthread->errors[2] ;
}

build_forum_counters($forumid);

// end make thread code