# Database Discussions > MySQL >  html form to phpBB

## Magnacarta

The name may suggest php, but this is pretty much an sql thing but I will be posting a thread over at webdeveloper.com just incase.
Essentially, I am creating a form that users enter data into, and when they click submit, that information is posted into a phpBB3 forum, as a new topic.
However I am not entirely sure how to do this. I believe you have to create a script that collects all of the data, then all of that form data is turned into one variable to fit in a single column (in this case post_body).

To try to explain myself a bit more. I have the following form:
http://dannyp2.ifastnet.com/application.php

A script that is used on an actual forum, it may only need  tweaking, but fields have been changed to reflect my form, however the script won't work until setup specifically for an html/php form.



```
<?php

$break_char = "\n";

// Change to suit the sotl forum

$post_into_forum_id = 7;
$post_from_user = 58;


$poll_title		    = "Allow this applicant?";
$poll_length		= 0 ;
$poll_max_options	=  1;
$poll_vote_change	=  0;

$cur_poll_options[0] = 'Yes';
$cur_poll_options[1] = 'No';

$poll_option_text	= implode($break_char, $cur_poll_options);





/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/message_parser.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('sotlapplication');
//$submit = request_var('submit','');
$submit = request_var('submit','');
if($submit)
{
// get all vars and save to posting
$charname               = utf8_normalize_nfc(request_var('charname','', true));
$class                  = utf8_normalize_nfc(request_var('class','', true));
$role                  	= utf8_normalize_nfc(request_var('role','', true));
$playstyle              = utf8_normalize_nfc(request_var('playstyle','', true));
$mainoralt              = utf8_normalize_nfc(request_var('mainoralt','', true));
$swtorname              = utf8_normalize_nfc(request_var('swtorname','', true));
$age            		= utf8_normalize_nfc(request_var('age','', true));
$gender           		= utf8_normalize_nfc(request_var('gender','', true));
$location               = utf8_normalize_nfc(request_var('location','', true));
$email          		= utf8_normalize_nfc(request_var('email','', true));
$teamspeak             	= utf8_normalize_nfc(request_var('teamspeak','', true));
$microphone             = utf8_normalize_nfc(request_var('microphone','', true));
$comments               = utf8_normalize_nfc(request_var('comments','', true));

$message = '';
$message .= 'Character Name :' . $charname . $break_char ;
$message .= 'Class :'.$class.$break_char;
$message .= 'Role :'.$role.$break_char;
$message .= 'Play Style :'.$playstyle.$break_char;
$message .= 'Main or Alt :'.$mainoralt.$break_char;
$message .= 'SWTOR forum name :'.$swtorname.$break_char;
$message .= 'Age :'.$age.$break_char;
$message .= 'Gender :'.$gender.$break_char;
$message .= 'Location :'.$location.$break_char;
$message .= 'Email address :'.$email.$break_char;
$message .= 'Teamspeak :'.$teamspeak.$break_char;
$message .= 'Microphone :'.$microphone.$break_char;
$message .= 'Additional Comments :'.$comments.$break_char;
:'.$break_char.$break_char.$break_char;
$message .= 'Automatically posted by ApplicationBot! :'.$break_char;

$subject = 'SOTL Application '.$name;

$sql = 'SELECT * FROM '.phpbb_users.' WHERE user_id='.$post_from_user;
$result = $db->sql_query($sql);
$post_from_user = $db->sql_fetchrow($result);
$db->sql_freeresult($result);

    //Get current users ip
    $sql = "SELECT session_ip FROM ".phpbb_sessions." WHERE session_user_id = ".$user->data['user_id'];
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $user_ip = $row['session_ip'];

    $forum = $post_into_forum_id; //De kennisbank dus

	// Parse the text with the bbcode parser and write into $text
	$text		= utf8_normalize_nfc($message);

	$uid			= $bitfield			= $options	= '';	// will be modified by generate_text_for_storage
	$allow_bbcode	= $allow_smilies	=	$allow_urls	= true;

	$user->add_lang('ucp');

	// Switch array keys, with values in welcome pm.
	$welcome_vars = array(
		'{USERNAME}'		=> $user->data['username'],
		'{USER_ID}'			=> $user->data['user_id'],
		'{SITE_NAME}'		=> $config['sitename'],
		'{SITE_DESC}'		=> $config['site_desc'],
		'{ROOT_PATH}'		=> $phpbb_root_path);

	$sql_ary = array(
		'forum_id'	                => $post_into_forum_id,
		'topic_title'               => $subject,
		'topic_poster'              => $post_from_user['user_id'],
		'topic_time'	            => time(),
		'topic_first_poster_name'	=> $post_from_user['username'],
		'topic_first_poster_colour' => $post_from_user['user_colour'],
		'topic_last_poster_id'	    => $post_from_user['user_id'],
		'topic_last_poster_name'	=> $post_from_user['username'],
		'topic_last_poster_colour'  => $post_from_user['user_colour'],
		'topic_last_post_subject'	=> $subject,
		'topic_last_post_time'	    => time(),
		);

	//Insert the data into the topics table
	$sql = 'INSERT INTO ' . phpbb_topics. ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
    $topic_id = $db->sql_nextid();

    $sql_ary = array(
		'user_id'	                => $post_from_user['user_id'],
		'topic_id'                  => $topic_id,
		'topic_posted'              => 1,
		);

	//Insert the data into the topics posted table
	$sql = 'INSERT INTO ' . phpbb_topics_posted . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
    $message_parser = new parse_message();
    $message_parser->message = $message;
    $message_parser->parse($allow_bbcode, $allow_urls, $allow_smilies);

    $sql_ary = array(
		'topic_id'		            => $topic_id,
		'forum_id'	                => $forum,
		'poster_id'	                => $post_from_user['user_id'],
		'poster_ip'	                => $user_ip,
		'post_time'	                => time(),
		'post_approved'             => 1,
		'post_subject'	            => $subject,
		'post_text'	                => $message_parser->message,
		'bbcode_bitfield'	        => $message_parser->bbcode_bitfield,
		'bbcode_uid'		        => $message_parser->bbcode_uid,
        'post_checksum'             => md5($message_parser->message),
		);

	//Insert the data into the posts table
	$sql = 'INSERT INTO ' . phpbb_posts . ' ' . $db->sql_build_array('INSERT', $sql_ary);
	$db->sql_query($sql);
$post_id = $db->sql_nextid();

	//Update the users topics table
    $poll = array(
		'poll_title'		=> $poll_title,
		'poll_length'		=> $poll_length,
		'poll_max_options'	=> $poll_max_options,
		'poll_option_text'	=> $poll_option_text,
		'poll_start'		=> time(),
		'poll_last_vote'	=> 0,
		'poll_vote_change'	=> 1,
		'enable_bbcode'		=> true,
		'enable_urls'		=> true,
		'enable_smilies'	=> true,
		'img_status'		=> 1
		);

    $parse_poll = new parse_message($poll['poll_title']);
	$parse_poll->bbcode_uid = $message_parser->bbcode_uid;
	$parse_poll->bbcode_bitfield = $message_parser->bbcode_bitfield;
	$message_parser->parse_poll($poll);

    $sql_poll = array(
		'poll_title'		=> $poll['poll_title'],
		'poll_start'		=> time(),
		'poll_max_options'	=> $poll['poll_max_options'],
		'poll_length'		=> ($poll['poll_length'] * 86400),
		'poll_vote_change'	=> 0,
        'topic_first_post_id' => $post_id,
        'topic_last_post_id' => $post_id,
		);
   $sql = 'UPDATE ' . TOPICS_TABLE . " SET " . $db->sql_build_array('UPDATE', $sql_poll) . " WHERE topic_id =" . $topic_id;
   $db->sql_query($sql);

   $size = sizeof($cur_poll_options);
   $sql_insert_ary=Array();

   for($i=0; $i<$size;$i++)
   {
    $sql_insert_ary[] = array(
						'poll_option_id'	=> (int) sizeof($cur_poll_options) + 1 + sizeof($sql_insert_ary),
						'topic_id'			=> $topic_id,
'poll_option_text'	=> (string) $cur_poll_options[$i],
                        'poll_option_total' => 0
					);
   }
   $db->sql_multi_insert(POLL_OPTIONS_TABLE, $sql_insert_ary);
	//Updating of the forums table
	$sql_ary = array(
'forum_last_post_id' => $post_id,					'forum_last_poster_id'=>post_from_user['user_id'],		'forum_last_post_subject'=>$subject,					'forum_last_post_time' => time(),
'forum_last_poster_name'	=> $post_from_user['username'],
'forum_last_poster_colour'=>$post_from_user['user_colour'],
);
	$sql = 'UPDATE ' . phpbb_forums . '
			SET ' . $db->sql_build_array('UPDATE', $sql_ary) . "
			WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . phpbb_forums . " SET forum_posts = forum_posts + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . phpbb_forums . " SET forum_topics = forum_topics + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . phpbb_forums . " SET forum_topics_real = forum_topics_real + 1 WHERE forum_id = $forum";
	$db->sql_query($sql);
	$sql = 'UPDATE ' . phpbb_users . " SET user_posts = user_posts + 1 WHERE user_id = ".$post_from_user['user_id'];
	$db->sql_query($sql);
	$topic_count = $config['num_topics'] + 1;
	set_config('num_topics', $topic_count);
	$post_count = $config['num_posts'] + 1;
	set_config('num_posts', $post_count);

    trigger_error($user->lang['POST_ADDED_POSTFORM']);
//==
}
else
{
    $form_key = 'formcheck';
    add_form_key($form_key);
    $template->assign_vars(array(
            'U_ACTION' => append_sid($phpbb_root_path.'sotlapplication.'.$phpEx),
            ));
}
?>
```

----------


## paullopez

I have checked your code where it shows, parse error: syntax error, unexpected ':' in CODE on line 73 Errors parsing CODE




> :'.$break_char.$break_char.$break_char;

----------


## Magnacarta

I managed to get it working in the end but thank you =]

Only problem is that it navigates to the forum after submission but I have it displaying a custom message that auto redirects back to the main website after 5 seconds =]

----------

