<HTML><HEAD><TITLE>MSP example: using a form to set up a database
query</TITLE></HEAD> 
<BODY BGCOLOR="#fbf2e7">

<H1>MSP example: using a form to set up a database query</H1>

<H2>Select person</H2>

<FORM METHOD=POST ACTION="dbquery.msp">
<BR>Select name: 
<SELECT NAME="person">
<?MSP$
let 
    val db = Postgres.openbase
	 { dbhost    = NONE,		(* database server host *)
	   dbname    = SOME "messages",	(* database name        *)
	   dboptions = NONE,		(* options              *)
	   dbport    = NONE,		(* database server port *)
	   dbpwd     = NONE,		(* user passwd          *)
	   dbtty     = NONE,		(* tty for error log    *)
	   dbuser    = SOME "nobody"	(* database user        *)
	 };

    val dbres = Postgres.execute db "SELECT DISTINCT name FROM message";
    val names = List.tabulate(Postgres.ntuples dbres, 
			      Postgres.getstring dbres 0)
    open Msp
    infix &&
in 
    prmap (fn name => option name && $name && Nl) names
end
?>

</SELECT>
<BR><INPUT TYPE=SUBMIT VALUE="Display messages">
</FORM>

<P>This form was generated by a mosml server pages script.  It will
invoke another mosml server pages script to compute and display the
set of messages requested.
</BODY>
</HTML>
