Listing 1. index.php

<%//////////// index.php ////////////////////////////

// if we just clicked EXIT PROGRAM,
// show exit screen and quit.

if (isset($goodbye)) {
   include ("./goodbye.php");
   }

include ("class.FastTemplate.php");
$tpl = new FastTemplate(".");

$tpl->define (array(main      => "main.tpl",
                form          => "form.tpl",
                select        => "select.tpl",
                option        => "option.tpl",
                submit        => "submit.tpl",
                textarea      => "textarea.tpl"));

$tpl->assign (array(TITLE     => "PHP SQL
                                       CODE TESTER",
                FORM_ACTION   => "mysql.php",
                FORM_METHOD   => "post",
                STRING1       => "DATABASE
                                       SELECTOR: ",
                STRING2       => "INPUT SQL QUERY
                                       BELOW: ",
                SELECT_NAME   => "database",
                SELECT_SIZE   => "1",
                SUBMIT_VAL    => "EXECUTE QUERY",
                TEXTAREA_NAME => "query",
                TEXTAREA_COLS => "40",
                TEXTAREA_ROWS => "3" ));

                              //Assumes MySQL.
$host="localhost";  //Adjust for your
$user="bill";       //setup in these
$password="megan";  //three lines.

mysql_connect($host, $user, $password);
$db_table = mysql_list_dbs();

// get local databases. append to selector options. //

for ($i = 0; $i < mysql_num_rows($db_table); $i++) {
    $optionval = mysql_tablename($db_table, $i);
    $tpl->assign(array(OPTION_TAG =>"$optionval"));
    $tpl->parse(OPTIONS, ".option");
    }

$tpl->parse(SELECT, "select");
$tpl->parse(TEXTAREA, "textarea");
$tpl->parse(SUBMIT, "submit");
$tpl->parse(BODY, "form");
$tpl->parse(MAIN, "main");

$tpl->FastPrint();
exit;
%>