wookie Posted February 21, 2008 Share Posted February 21, 2008 I'm trying to run this automated script that posts a new topic to a forum, using info gained via an sql query. The part of this script that actually posts at the forum is "test" from this line "$msgBody = 'test';" How do I add the following query so that the results are posted instead of "test"? Here's the query.. $result = mysql_query("SELECT * FROM smf_messages WHERE ID_BOARD='1'"); while($row = mysql_fetch_array($result)) { <?php include_once('/absolute path/SSI.php'); require_once($sourcedir . '/Post.php'); require_once($sourcedir . '/Subs-Post.php'); // comment out below line to run in shell if (!isset($context['user']) || !$context['user']['is_admin']) die ('Unknown error 744 has occurred'); $topic = 0; // set to 0 for new topic, set to a topic id to reply $board = 1; // set to valid board id $ID_MEMBER = 1; $_POST['subject'] = 'you\'re okay'; // the notify function uses this $msgSubject = addslashes($_POST['subject']); $msgBody = 'test'; $msgBody = prepBody( $msgBody); $msgOptions = array( 'id' => 0, // set id to modify 'subject' => $msgSubject, 'body' => $msgBody, 'icon' => 'xx', // look at smf_message_icons table to see all possible values 'smileys_enabled' => 1, 'attachments' => empty($attachIDs) ? array() : $attachIDs, ); $topicOptions = array( 'id' => empty($topic) ? 0 : $topic, 'board' => $board, 'poll' => null, 'lock_mode' => 0, 'sticky_mode' => null, 'mark_as_read' => true, ); $posterOptions = array( 'id' => $ID_MEMBER, 'name' => 'some name', 'email' => 'me@domain.com', 'update_post_count' => 1 ); $newTopic = empty($topic) || $topic == 0; createPost($msgOptions, $topicOptions, $posterOptions); if (isset($topicOptions['id'])) $topic = $topicOptions['id']; if ($newTopic) notifyMembersBoard(); else sendNotifications($topic, 'reply'); redirectexit('topic=' . $topic); // take an htmlized $txt and turn it into a smf compatible msg // no cr lf, no html tags, <br> turned into <br /> and <p> made into <br /><br /> function prepBody( $txt) { // cr lf to spaces $txt = str_replace( "\r", ' ', $txt); $txt = str_replace( "\n", ' ', $txt); // reduce blank spaces $txt = preg_replace( '/[ ][ ]+/', ' ', $txt); // turn <br> or <br /> into \n $txt = preg_replace( '!s*<br(s*/)?>\s*!i', "\n", $txt); // turn <p ...> and <p> into \n\n $txt = preg_replace( '/\s*<p([^>]+|)>\s*/i', "\n\n", $txt); // mercilessly strip all other html $txt = preg_replace( '/<[^>]+>/', '', $txt); $txt = preg_replace( '!</[a-z]+>!i', '', $txt); // turn \n back to <br /> $txt = str_replace( "\n", '<br />', trim( $txt)); return addslashes($txt); } ?> Many thanks in advance! Wookie Quote Link to comment https://forums.phpfreaks.com/topic/92223-automating-new-post-at-forum-using-sql/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.