You have to return html instead of echoing it. Buffer output withing your function and return it:
function shortcode_output() {
ob_start();
//get stuff from database
//format stuff
echo <<<FORM
<form method="POST" action="blah.php">
<!--more html-->
</form>
FORM;
$html = ob_get_contents();
ob_end_clean();
return $html;
}