Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-02-2011, 05:52 PM
Killa878 Killa878 is offline
 
Join Date: Nov 2009
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Insert Thread into database.

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:

Code:
	private function MakeThread( $ForumId, $Title, $Content )
	{
		mysql_query( "INSERT INTO `thread` (`threadid`,`title`,`prefixid`,`firstpostid`,`lastpostid`,`lastpost`,`forumid`,`pollid`,`open`,`replycount`,`hiddencount`,`deletedcount`,`postusername`,`postuserid`,`lastposter`,`dateline`,`lastedit`,`views`,`iconid`,`notes`,`visible`,`sticky`,`votenum`,`votetotal`,`attach`,`similar`,`taglist`,`vbseo_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`,`allowsmilie`,`showsignature`,`ipaddress`,`iconid`,`visible`,`attach`,`infraction`,`reportthreadid`,`htmlstate`) 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
Reply With Quote
  #2  
Old 07-02-2011, 06:43 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).
Reply With Quote
  #3  
Old 07-02-2011, 07:05 PM
Killa878 Killa878 is offline
 
Join Date: Nov 2009
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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.
Reply With Quote
  #4  
Old 07-02-2011, 07:48 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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?
Reply With Quote
  #5  
Old 07-02-2011, 07:51 PM
Killa878 Killa878 is offline
 
Join Date: Nov 2009
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by kh99 View Post
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
i just did a re-count and got 31 columns and 31 values.

Im stumped on this.
Reply With Quote
  #6  
Old 07-02-2011, 11:08 PM
BirdOPrey5's Avatar
BirdOPrey5 BirdOPrey5 is offline
Senior Member
 
Join Date: Jun 2008
Location: New York
Posts: 10,610
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Check out my "New Thread on User Banning" 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.

Code:
$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
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:04 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03837 seconds
  • Memory Usage 2,215KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete