WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Point and Click Interface ala MS Access for creating SQL statements.
Categories : MySQL, Complete Programs, General SQL, PHP, Databases Update Picture
Mike Kachline
Date : Sep 14th 1998
Grade : 2 of 5 (graded 4 times)
Viewed : 21922
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Mike Kachline
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<html>
<?
/*
* mysql.phtml (Mon Sep 14 04:17:00 EDT 1998)
* Mike Kachline (kachline@cc.gatech.edu)
* Webified User Interface for manipulating MySQL databases, queries and
tables.
*
* Legal Stuff:
* This Software is Free Software. Please see GNU Liscencing Information for
more
* details. You may use this software as you see fit, subject only that my
name
* remains in the credits. :)
*
* Testing:
* * SQL Developed from specifications for MySQL 3.22.7-beta.
* * Tested under Mysql 3.21.31 and PHP 3.0 (Probably works under PHP 2.0)
* * Written from scratch in about 3 days, so, parts may still be
unimplemented.
*
* Usage:
* * Make sure that the user whom your web server is running also has
rights to one (or many) of
* your mysql tables ("test" database should work).
* * Save this file as "mysql.phtml".
* * Fire up "mysql.phtml" in your web browser.
* * Have fun.
*
* Notes:
* This software only creates the final SQL right now. No SQL is actually
executed. Yes,
* I know, doing so is trivial, but I want to implement the database security
stuff correctly first.
*
*
*/


/*
* Save the state of our query.
*/
Function QueryTables_SaveState($database_param = "")
{
echo "\n\n";
/*
* QueryTablesUI_1
*
*/
global $tablecount;
global $fields;
global $fieldcount;
global $formaction;
if(strlen($database_param) <= 0) {
global $database;
} else {
$database = $database_param;
};


/* Remember Database */
echo "<input type=\"hidden\" name=\"database\" value=\"" .
HTMLSpecialChars($database) . "\">\n";
if($formaction == "QueryTablesUI_1") {
return;
};






/*
* QueryTablesUI_2
*
*/
/* Remember which tables we're using */
if( strlen($tablecount) > 0) {
echo "<input type=\"hidden\" name=\"tablecount\" value=\"" .
HTMLSpecialChars($tablecount) . "\">\n";
for($i = 0; $i < $tablecount; $i++) {
$thistable = "table_" . $i;
global $$thistable;
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thistable) . "\" value=\"" . HTMLSpecialChars($$thistable) . "\">\n";
};
};


if($formaction == "QueryTablesUI_2") {

/* Save all tables we're looking for */
global $querytables;
$tablecount = count($querytables);
echo "<input type=\"hidden\" name=\"tablecount\" value=\"" .
HTMLSpecialChars($tablecount) . "\">\n";
for ($i = 0; $i < $tablecount; $i++) {
echo "<input type=\"hidden\" name=\"table_" . $i . "\"
value=\"" . HTMLSpecialChars($querytables[$i]) ."\">\n";
};

return;
};



/*
* QueryTablesUI_3
*
*/

/* Remember which fields we want */
if($formaction == "QueryTablesUI_3") {
$fieldcount = count($fields);
for($i = 0; $i < $fieldcount; $i++) {
echo "<input type=\"hidden\" name=\"field_" . $i . "\"
value=\"" . HTMLSpecialChars($fields[$i]) . "\">\n";
};

} else {
for($i = 0; $i < $fieldcount; $i++) {
$thisfield = "field_" . $i;
global $$thisfield;
echo "<input type=\"hidden\" name=\"field_" . $i . "\"
value=\"" . HTMLSpecialChars($$thisfield) . "\">\n";
};
};
echo "<input type=\"hidden\" name=\"fieldcount\" value=\"" .
HTMLSpecialChars($fieldcount) . "\">\n";
if($formaction == "QueryTablesUI_3") {
return;
};



/*
* QueryTablesUI_4
*
*/


/* Remember conditional fields */
for($i = 0; $i < $fieldcount; $i++) {
$thiscondition = "conditionalfield_" . $i;
global $$thiscondition;
if( strlen($$thiscondition) > 0) {
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thiscondition) . "\" value=\"" . HTMLSpecialChars($$thiscondition) . "\">\n";
};
};



/* Remember conditions */
for($i = 0; $i < $fieldcount; $i++) {
for($j = 0; $j < $fieldcount; $j++) {
$thiscondition = "conditional_" . $i . "_" . $j;
global $$thiscondition;
if( strlen($$thiscondition) > 0) {
echo "<input type=\"hidden\" name=\"" .
HTMLSpecialChars($thiscondition) . "\" value=\"" . HTMLSpecialChars
($$thiscondition) . "\">\n";
};

};
};
if($formaction == "QueryTablesUI_4") {
return;
};




/*
* QueryTablesUI_5
*
*/

for($i = 0; $i < 15; $i++) {
$thisjoinfrom = "joinfrom_" . $i;
$thisjoinjoin = "joinjoin_" . $i;
$thisjointo = "jointo_" . $i;
$thisjoinfrom_on = "joinfrom_on_" . $i;
$thisjointo_on = "jointo_on_" . $i;
global $$thisjoinfrom;
global $$thisjoinjoin;
global $$thisjointo;
global $$thisjoinfrom_on;
global $$thisjointo_on;

if( (strlen($$thisjoinfrom) > 0)
&& (strlen($$thisjoinjoin) > 0)
&& (strlen($$thisjointo) > 0)) {

echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisjoinfrom) . "\" value=\"" . HTMLSpecialChars($$thisjoinfrom) . "\">\n";
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisjoinjoin) . "\" value=\"" . HTMLSpecialChars($$thisjoinjoin) . "\">\n";
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisjointo) . "\" value=\"" . HTMLSpecialChars($$thisjointo) . "\">\n";
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisjoinfrom_on) . "\" value=\"" . HTMLSpecialChars($$thisjoinfrom_on) . "\">
\n";
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisjointo_on) . "\" value=\"" . HTMLSpecialChars($$thisjointo_on) . "\">\n";


};

};
if($formaction == "QueryTablesUI_5") {
return;
};



/*
* QueryTablesUI_6
*
*/
for($i=0; $i < 5; $i++) {
$thisgroupby = "groupby_" . $i;
$thisorderby = "orderby_" . $i;
$thisorderbyorder = "orderbyorder_" . $i;
global $$thisgroupby;
global $$thisorderby;
global $$thisorderbyorder;

if( strlen($$thisgroupby) > 0) {
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisgroupby) . "\" value=\"" . HTMLSpecialChars($$thisgroupby) . "\">\n";
};

if( (strlen($$thisgroupby) > 0) &&
(strlen($$thisorderbyorder) > 0)) {
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisorderby) . "\" value=\"" . HTMLSpecialChars($$thisorderby) . "\">\n";
echo "<input type=\"hidden\" name=\"" . HTMLSpecialChars
($thisorderbyorder) . "\" value=\"" . HTMLSpecialChars($$thisorderbyorder) .
"\">\n";
};



};
for($i = 0; $i < $fieldcount; $i++) {
$thisas = "fieldas_" . $i;
global $$thisas;
echo "<input type=\"hidden\" name=\"" . $thisas . "\" value=\""
. $$thisas . "\">\n";
};
if($formaction == "QueryTablesUI_6") {
return;
};





/*
* QueryTablesUI_7
*
*/
if($formaction == "QueryTablesUI_7") {
return;
};



};



/*
* What tables do we want?
*/
Function QueryTablesUI_1()
{
global $database;
echo "<h3> Get Data From Which Tables? </h3>\n";
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTablesUI_2
\">\n";
$formaction = "QueryTablesUI_1";
QueryTables_SaveState($database);


/* Pick from all tables */
$recordset = mysql_listtables($database);
$rowcount = mysql_NumRows($recordset);
echo "<select multiple name=\"querytables[]\">\n";
for($i = 0; $i < $rowcount ; $i++) {
echo "<option>" . mysql_tablename($recordset,$i);
};
echo "</select>";

echo "<input type=\"submit\">";



echo "</form>\n";
};




/*
* What fields do we want?
*/
Function QueryTablesUI_2()
{
global $database;
global $querytables;
echo "<h3> Display Which Fields? </h3>\n";
echo "<form method=\"post\" action=\"mysql.phtml\">";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTablesUI_3
\">\n";
echo "<input type=\"submit\">";
QueryTables_SaveState();
echo "<hr>";



/* Create a list of possible fields. */
echo "<select multiple name=\"fields[]\">\n";
$tablecount = count($querytables);
for($i = 0; $i < $tablecount; $i++) {
$thistable = $querytables[$i];
$recordset = mysql_listfields($database, $thistable);
$rowcount = mysql_numfields($recordset);
for($j = 0; $j < $rowcount; $j++) {
echo "<option>" . $thistable . "." . mysql_fieldname
($recordset, $j);
};
Unset($recordset);
Unset($thistable);
};
echo "</select>\n";


echo "</form>\n";
};




/*
* Limit results to conditions.
*/
Function QueryTablesUI_3()
{
global $database;
global $fields;
global $tablecount;



echo "<h3> Limit Results to What Conditions? </h3>\n";
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
if($tablecount > 1) {
echo "<input type=\"hidden\" name=\"formaction\" value=
\"QueryTablesUI_4\">\n";
} else {
echo "<input type=\"hidden\" name=\"formaction\" value=
\"QueryTablesUI_5\">\n";
};
echo "<input type=\"submit\">";
echo "<hr>";
QueryTables_SaveState();






/* All possible fields */
$fieldcount = count($fields);
echo "<table border>\n";
echo "<tr>";
for( $i = 0; $i < $fieldcount; $i++) {
echo "<td><select name=\"conditionalfield_" . $i . "\">";
echo "<option>";
for($j = 0; $j < $fieldcount; $j++) {
echo "<option>" . $fields[$j];
};
echo "</select></td>\n";

};
echo "</tr>\n";

for($i = 0; $i < $fieldcount; $i++) {
echo "<tr>";
for($j = 0; $j < $fieldcount; $j++) {
echo "<td><input name=\"conditional_" . $i . "_" . $j .
"\"></td>";
};
echo "</tr>\n";
};


echo "</table>";

echo "</form>";

};




/*
* How are these tables related?
*/
Function QueryTablesUI_4()
{
global $database;
global $tablecount;

echo "<form method=\"post\" action=\"mysql.phtml\">";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTablesUI_5
\">\n";
echo "<h3> How are these tables related? </h3>\n";
echo "<input type=\"submit\">\n";
echo "<hr>";


QueryTables_SaveState();



/* Get a list of all table and field options */
$tableoptions = "<option>";
$fieldoptions = "<option>";
for($i = 0; $i < $tablecount; $i++) {
$thistable = "table_" . $i;

global $$thistable;
$tableoptions = $tableoptions . "<option>" . $$thistable;
$recordset = mysql_listfields($database, $$thistable);
$rowcount = mysql_numfields($recordset);
for($j = 0; $j < $rowcount; $j++) {
$fieldoptions = $fieldoptions . "<option>" .
$$thistable . "." . mysql_fieldname($recordset, $j);
};
Unset($recordset);
Unset($thistable);
Unset($rowcount);
};




echo "<table border>\n";
echo "<tr>";
echo "<td>Table</td>";
echo "<td>Join Type</td>";
echo "<td>Table</td>";
echo "<td>Joined on</td>";
echo "<td>Table.Field</td>";
echo "<td>=</td>";
echo "<td>Table.Field</td>";
echo "</tr>\n";

for($i = 0; $i < 15; $i++) {
echo "<tr>";

/* From table */
echo "<td><select name=\"joinfrom_" . $i . "\">";
echo $tableoptions;
echo "</select></td>";

/* Join type */
echo "<td><select name=\"joinjoin_" . $i . "\">";
echo "<option>";
echo "<option>Cross Join";
echo "<option>Straight_Join";
echo "<option>Left Join";
echo "<option>Left Outer Join";
echo "</select></td>";

/* To Table */
echo "<td><select name=\"jointo_" . $i . "\">";
echo $tableoptions;
echo "</select></td>";


/* On */
echo "<td>Joined On</td>";

/* Foo = Bar */
echo "<td><select name=\"joinfrom_on_" . $i . "\">";
echo $fieldoptions;
echo "</select></td>";

echo "<td>=</td>";

echo "<td><select name=\"jointo_on_" . $i . "\">";
echo $fieldoptions;
echo "</select></td>";



echo "</tr>";
};




echo "</table>\n";
echo "</form>";
};



/*
* Group by / Order by.
*/
Function QueryTablesUI_5()
{
global $database;
global $tablecount;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<h3>Data Grouping and Ordering</h3>\n";
echo "<input type=\"submit\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTablesUI_6
\">\n";
echo "<hr>\n";
QueryTables_SaveState();


/* Get our select strings */
$tableoptions = "<option>";
$fieldoptions = "<option>";
for($i = 0; $i < $tablecount; $i++) {
$thistable = "table_" . $i;
global $$thistable;
$tableoptions = $tableoptions . "<option>" . $$thistable;
$recordset = mysql_listfields($database, $$thistable);
$rowcount = mysql_numfields($recordset);
for($j = 0; $j < $rowcount; $j++) {
$fieldoptions = $fieldoptions . "<option>" .
$$thistable . "." . mysql_fieldname($recordset, $j);
};
Unset($recordset);
Unset($thistable);
};
echo "</select>\n";


/* Group By */
echo "<h4>Group Data by</h4>";
echo "<table noborder>\n";
echo "<tr>";
echo "<td><select name=\"groupby_0\">";
echo $fieldoptions;
echo "</select></td>";
for($i = 1; $i < 5; $i++) {
echo "<td> Then </td>";
echo "<td><select name=\"groupby_" . $i . "\">";
echo $fieldoptions;
echo "</select></td>";
};
echo "</tr>";
echo "</table>";



/* Order By */
echo "<h4>Order Data by</h4>";
echo "<table border>\n";
echo "<tr>";

echo "<td><select name=\"orderby_0\">";
echo $fieldoptions;
echo "</select>";

echo "<select name=\"orderbyorder_0\">";
echo "<option value=\"ASC\">Ascending";
echo "<option value=\"DESC\">Descending";
echo "</select></td>";


for($i = 1; $i < 5; $i++) {
echo "<td> Then </td>";
echo "<td><select name=\"orderby_" . $i . "\">";
echo $fieldoptions;
echo "</select>";

echo "<select name=\"orderbyorder_" . $i . "\">";
echo "<option>Ascending";
echo "<option>Descending";
echo "</select>";


echo "</td>";



};



echo "</tr>";
echo "</table>";


echo "</form>\n";
};



/*
* Miscellaneous stuff.
*/
Function QueryTablesUI_6()
{
global $database;
global $fieldcount;
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTablesUI_7
\">";
echo "<h3>Miscellaneous Options </h3>\n";
echo "<input type=\"submit\">\n";
QueryTables_SaveState();
echo "<hr>\n";

echo "<h4>Column Naming and Ordering</h4>\n";
echo "<table border>\n";
echo "<tr>";
echo "<td>Field Name</td>";
echo "<td>Column Number</td>";
echo "<td>Call this Column....</td>";
echo "</tr>";
for($i = 0; $i < $fieldcount; $i++) {
$thisfield = "field_" . $i;
global $$thisfield;

echo "<tr>";
echo "<td>" . $$thisfield . "</td>";
echo "<td>Unimplemented</td>";
echo "<td> <input name=\"fieldas_" . $i . "\" value=\"" .
$$thisfield . "\"></td>";
echo "</tr>";
};
echo "</table>";

echo "<h4>Having Clause (Optional) </h4>\n";
echo "Having:";
echo "<input name=\"having\"><br>\n";

echo "<h4>Data Display Limits (Optional) </h4>\n";
echo "Start Displaying at Row:";
echo "<input name=\"start_row\" value=\"0\">\n";
echo " For ";
echo "<input name=\"row_count\" value=\"Unlimited\">";
echo "Rows.";




echo "</form>\n";

};






/*
* Make sure this is what we want. Also put our SQL statement together.
*/
Function QueryTablesUI_7()
{
global $database;
global $tablecount;
global $fieldcount;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"QueryTables\">
\n";
echo "<h3>Run This Query?</h3>\n";
echo "<input type=\"submit\">\n";
QueryTables_SaveState();
echo "<hr>\n";




/* SELECT fields */
for($i = 0; $i < $fieldcount; $i++) {
$thisfield = "field_" . $i;
$thisas = "fieldas_" . $i;
global $$thisfield;
global $$thisas;
$selects = $selects . "," . $$thisfield;
if( IsSet($$thisas)) {
if( $$thisfield != $$thisas) {
$selects = $selects . " AS '" . strtr
($$thisas, " ", "_") . "'";
};
};
};
$selects = substr($selects, 1, strlen($selects));
$selects = "SELECT " . $selects;



/* FROM froms */
if($tablecount == 1) {
/* Just one table. */
global $table_0;
$froms = " FROM " . $table_0;
} else {
/* We've got joins */
for($i = 0; $i < 5; $i++) {
$thisjoinfrom = "joinfrom_" . $i;
$thisjoinjoin = "joinjoin_" . $i;
$thisjointo = "jointo_" . $i;
$thisjoinfrom_on = "joinfrom_on_" . $i;
$thisjointo_on = "jointo_on_" . $i;
global $$thisjoinfrom;
global $$thisjointo;
global $$thisjoinjoin;
global $$thisjoinfrom_on;
global $$thisjointo_on;

if(
(strlen($$thisjoinfrom) > 0) &&
(strlen($$thisjoinjoin) > 0) &&
(strlen($$thisjointo) > 0) ) {

/* We've got a straight join. */
if( ($$thisjoinjoin == "Join") ||
($$thisjoinjoin == "Cross Join") ||
($$thisjoinjoin == "Inner_Join")) {
$froms = $froms . "," . $$thisjoinfrom
. " " . $$thisjoinjoin . " " . $$thisjointo;
} else {
/* We've got a conditional join */
$froms = $froms . "," . $$thisjoinfrom
. " " . $$thisjoinjoin . " " . $$thisjointo . " ON " . $$thisjoinfrom_on . "="
. $$thisjointo_on;

};
};
};
$froms = substr($froms, 1, strlen($froms));
$froms = " FROM " . $froms;

};



/* WHERE wheres */
$wheres = " WHERE (";
for($i = 0; $i < 15; $i++) {
$thisfield = "conditionalfield_" . $i;
global $$thisfield;
if( strlen($$thisfield) <= 0) {
continue;
};


if($i > 0) {
$wheres = $wheres . ") OR (";
} else {
$wheres = $wheres . "(";
};

for($j = 0; $j < 15; $j++) {
$thiscell = "conditional_" . $j . "_" . $i;
global $$thiscell;
if( strlen($$thiscell) <= 0) {
continue;
} else {
if($j > 0) {
$wheres = $wheres . " AND (" .
$$thisfield . " " . $$thiscell . ")";
} else {
$wheres = $wheres . "(" . $$thisfield
. " " . $$thiscell . ")";
};
};
};
$wheres = $wheres . ")";
};
if($wheres == " WHERE (") {
Unset($wheres);
} else {
$wheres = $wheres . ")";
};



/* GROUP BY groupbys */
for($i = 0; $i < 5; $i++) {
$thisgroupby = "groupby_" . $i;
global $$thisgroupby;
if( strlen($$thisgroupby) > 0) {
$groupbys = $groupbys . "," . $$thisgroupby;
};
};
$groupbys = substr($groupbys, 1, strlen($groupbys));
$groupbys = " GROUP BY " . $groupbys;

if($groupbys == " GROUP BY ") {
Unset($groupbys);
};



/* HAVING havings */
$havings = " HAVING ";
global $having;
if( strlen($having) > 0) {
$havings = " HAVING " . $having;
};
if($havings == " HAVING ") {
Unset($havings);
};



/* ORDER BY orderbys */
for($i = 0; $i < 5; $i++) {
$thisorderby = "orderby_" . $i;
$thisorderbyorder = "orderbyorder_" . $i;
global $$thisorderby;
global $$thisorderbyorder;

if( strlen($$thisorderby) > 0) {
$orderbys = $orderbys . "," . $$thisorderby . " " .
$$thisorderbyorder;
};
};
$orderbys = substr($orderbys, 1, strlen($orderbys));
$orderbys = " ORDER BY " . $orderbys;
if($orderbys == " ORDER BY ") {
Unset($orderbys);
};



/* LIMIT limits */
$limits = " LIMIT ";
global $start_row;
global $row_count;

if($row_count == "Unlimited") {
Unset($row_count);
};
if($start_row == 0) {
Unset($start_row);
};
if( (strlen($start_row) > 0) && (strlen($row_count) > 0)) {
$start_row = $start_row . ",";
} else {
Unset($start_row);
};
$limits = $limits . $start_row . $row_count;
if( $limits == " LIMIT ") {
Unset($limits);
};



$sql = $selects . $froms . $wheres . $groupbys . $havings . $orderbys .
$limits;
echo "<h4> SQL To Execute </h4>\n";
echo "<textarea name=\"sql\" rows=\"10\" cols=\"90\">" . $sql .
"</textarea><br>\n";

};





Function QueryTables()
{
global $database;
global $sql;
ListData("", "", "", $sql, "", "asc");

};


/*
* Get Database name from user.
*/
Function InsertDatabaseUI_1()
{
echo "<h3>Add New Database</h3>";
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=
\"InsertDatabaseUI_2\">\n";
echo "Database Name:<input type=\"text\" name=\"database\"><br>\n";
echo "<input type=\"submit\">";
echo "</form>";
};



/*
* Confirm Database Creation.
*/
Function InsertDatabaseUI_2()
{



global $database;
$sql = "CREATE DATABASE " . strtr($database, " ", "_");


echo "<h3>Create New Database?</h3>";
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=
\"InsertDatabase\">\n";
echo "<textarea name=\"SQL\" cols=\"90\" rows=\"10\">$sql</textarea>";
echo "<input type=\"submit\">";
echo "</form>";
};



/*
* Actually create our database
*/
Function InsertDatabase()
{
echo "Create Database Here.";
};




/*
* ListTables -
* List all tables in $database.
*/
Function ListTables($database)
{


/* Define this to be the mysql database you are using. */
/* Then uncomment it. */

/* include("libs/header.phtml"); */
/* include("libs/gtmswww.phtml"); */
echo "<h3> Tables in $database </h3>";

/* List all GTMS tables */
$recordset = mysql_listtables($database);
$recordcount = mysql_NumRows($recordset);
$i = 0;
while($i < $recordcount) {
echo "<a href=tabledata.phtml?table=", mysql_tablename
($recordset,$i),">";
echo mysql_tablename($recordset,$i), "</a><br>\n";
$i++;
}


};




/*
* InsertTableUI -
* Creates a UI for ading a new table.
*/
Function InsertTableUI_1()
{

global $database;

echo "<form method=\"post\" action=\"mysql.phtml\">";
echo "<input type=\"hidden\" name=\"formaction\" value=\"InsertTableUI_2
\">\n";
echo "<h3> Create New Table for Database $database</h3>";
echo "Table Name:<input type=\"text\" name=\"tablename\">";
echo "<input type=\"submit\">";
echo "<input type=\"hidden\" name=\"database\" value=\"$database\">\n";
echo "<hr>\n";




echo "<table border>";
echo "<tr>";
echo "<td>Field Name</td>";
echo "<td>Field Type</td>";
echo "<td>Allow Null Values?</td>";
echo "<td>Primary Key?</td>";
echo "</tr>";


for( $i = 0; $i < 15; $i++) {
echo "<tr>";

/* This Field's Name */
echo "<td><input type=\"text\" name=\"fieldname_$i\"></td>";

/* This Field's Types */
echo "<td><select name=\"datatype_$i\">";
echo "<option value=\"TinyInt\">Tiny Integer (1 byte)";
echo "<option value=\"SmallInt\">Small Integer (2 bytes)";
echo "<option value=\"MediumInt\">Medium Integer (3 bytes)";
echo "<option value=\"Integer\">Integer (4 bytes)";
echo "<option value=\"BigInt\">Big Integer (8 bytes)";
echo "<option value=\"Float\">Floating Point (4 bytes)";
echo "<option value=\"Double Precision\">Double Precision (8
bytes)";
echo "<option value=\"Real\">Real (8 bytes)";
echo "<option value=\"Decimal\">Decimal (*Length* bytes)";
echo "<option value=\"Numeric\">Numeric (*Length* bytes)";
echo "<option value=\"Timestamp\">Timestamp (4 bytes)";
echo "<option value=\"Date\">Date (3 bytes)";
echo "<option value=\"Time\">Time (3 bytes)";
echo "<option value=\"DateTime\">DateTime (8 bytes)";
echo "<option value=\"Year\">Year (1 byte)";
echo "<option value=\"Char\">Char (*Length* bytes)";
echo "<option value=\"VarChar\">VarChar (*Length + 1* bytes)";
echo "<option value=\"TinyText\">TinyText (*Length + 1* bytes)";
echo "<option value=\"TinyBlob\">TinyBlob (*Length + 1* bytes)";
echo "<option value=\"Text\">Text (*Length + 2* bytes)";
echo "<option value=\"Blob\">Blob (*Length + 2* bytes)";
echo "<option value=\"MediumText\">MediumText (*Length + 3*
bytes)";
echo "<option value=\"MediumBlob\">MediumBlob (*Length + 3*
bytes)";
echo "<option value=\"LongText\">LongText (*Length + 4* bytes)";
echo "<option value=\"LongBlob\">LongBlob (*Length + 4* bytes";
echo "<option value=\"Enum\">Enum (1 or 2 bytes)";
echo "<option value=\"Set\">Set (1,2,3,4 or 8 bytes)";

echo "</select></td>";


/* Allow Nulls? */
echo "<td><input type=\"checkbox\" name=\"allownull_$i\"
\"checked\"></td>";

/* Primary Key? */
echo "<td><input type=\"radio\" name=\"primary_key\" value=
\"$i\"></td>";
echo "</tr>\n";
};
echo "</table>";

/* Save button */


echo "</form>\n";
};




/*
* Get more specific with field types.
*/
Function InsertTableUI_2()
{
echo "<html>\n";
echo "<h3>Field Type Information</h3>";
echo "<form action=\"mysql.phtml\" method=\"post\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"InsertTableUI_3
\">\n";

/* Save our current state */
global $database;
global $tablename;
global $primary_key;
$database = strtr($database, " ", "_");
$tablename= strtr($tablename, " ", "_");
$primary_key = strtr($primary_key, " ", "_");

echo "<input type=\"hidden\" name=\"database\" value=\"" . $database .
"\">\n";
echo "<input type=\"hidden\" name=\"tablename\" value=\"" . $tablename.
"\">\n";
echo "<input type=\"hidden\" name=\"primary_key\" value=\"" .
$primary_key. "\">\n";
echo "<H3> $database:$tablename </h3>\n";


echo "<table border>\n";
for($i = 0; $i < 15; $i++) {

$thisfieldname = "fieldname_" . $i;
$thisdatatype = "datatype_" . $i;
$thisfieldnull = "allownull_" . $i;
global $$thisfieldname;
global $$thisdatatype;
global $$thisfieldnull;
$$thisfieldname = strtr($$thisfieldname, " ", "_");


/* Don't go on if this field exists */
if( strlen($$thisfieldname) <= 0) {
continue;
};

echo "\n\n<!-- " . $$thisfieldname . " -->\n";
echo "<tr>";
echo "<td>" . $$thisfieldname . "</td>";
echo "<td>" . $$thisdatatype . "</td>";


/* Primary Key or NULL status */
if( $primary_key == $i) {
echo "<td> Primary Key </td>";
} else if( $$thisfieldnull == "off") {
echo "<td>No NULL Values</td>";
} else {
echo "<td>Allow NULL Values</td>";
};

/* Integer */
if( $$thisdatatype == "TinyInt" ||
$$thisdatatype == "SmallInt" ||
$$thisdatatype == "MediumInt" ||
$$thisdatatype == "Int" ||
$$thisdatatype == "Integer" ||
$$thisdatatype == "BigInt") {
echo "<td> Unsigned Values Only? <input type=
\"checkbox\" name=\"dataunsigned_$i\"></td>";
echo "<td> Zero Fill? <input type=\"checkbox\" name=
\"datazerofill_$i\"></td>";
};


/* Floating Points */
if( $$thisdatatype == "Float" ||
$$thisdatatype == "Double" ||
$$thisdatatype == "Double Precision" ||
$$thisdatatype == "Real" ||
$$thisdatatype == "Decimal" ||
$$thisdatatype == "Numeric" ) {
echo "<td> Decimals Printed: <input type=\"text\" name=
\"datadecimals_$i\" value=\"4\"></td>";
echo "<input type=\"hidden\" name=\"datalength_$i\"
value=\"12\">";
};


/* Timestamp */
if( $$thisdatatype == "Timestamp") {
/* Do nothing */
};


/* Chars */
if( $$thisdatatype == "Char" ||
$$thisdatatype == "VarChar") {
echo "<td> String Length (1 - 255): <input type=
\"text\" name=\"datalength_$i\" value=\"50\"></td>";
echo "<td> Binary Storage?<input type=\"checkbox\" name=
\"databinary_$i\"></td>";
};


/* Enum / Set */
if( $$thisdatatype == "Enum" ||
$$thisdatatype == "Set") {
echo "<td> <input type=\"text\" name=\"dataenum_
$i\"></td>";
};



echo "</tr>\n";


echo "<input type=\"hidden\" name=\"$thisfieldname\" value=\""
. $$thisfieldname . "\">\n";
echo "<input type=\"hidden\" name=\"$thisdatatype\" value=\"" .
$$thisdatatype . "\">\n";
echo "<input type=\"hidden\" name=\"$thisfieldnull\" value=\""
. $$thisfieldnull . "\">\n";
};
echo "</table>\n";



/* Go to next form */
echo "<input type=\"submit\">";


echo "</form>\n";
echo "</html>\n";
};







/*
* Set up our Indeces.
*/
Function InsertTableUI_3()
{
global $database;
global $tablename;
global $primary_key;

echo "<h3>Set up Indeces</h3>";
echo "<form method=\"post\" action=\"mysql.phtml\">";

echo "<input type=\"hidden\" name=\"formaction\" value=\"InsertTableUI_4
\">\n";
echo "<input type=\"hidden\" name=\"database\" value=\"" . $database .
"\">\n";
echo "<input type=\"hidden\" name=\"tablename\" value=\"" . $tablename
. "\">\n";
echo "<input type=\"hidden\" name=\"primary_key\" value=\"" .
$primary_key. "\">\n";
echo "<table border>";
echo "<tr>";
echo "<td>Field Name</td>";
echo "<td>Field Type</td>";
echo "<td>Not Indexed</td>";
echo "<td>Indexed (Duplicates Allowed)</td>";
echo "<td>Indexed (Duplicates Not Allowed)</td>";



for ($i = 0; $i < 15; $i++) {

/* Save our state */
$thisfieldname = "fieldname_" . $i;
$thisdatatype = "datatype_" . $i;
$thisfieldnull = "allownull_" . $i;
$thisdefault = "default_" . $i;
$thisdatalength = "datalength_" . $i;
$thisdataunsigned = "dataunsigned_" . $i;
$thisdatazerofill = "datazerofill_" . $i;
$thisdatadecimals = "datadecimals_" . $i;
$thisdatabinary = "databinary_" . $i;
$thisdataenum = "dataenum_" . $i;

global $$thisfieldname;
global $$thisdatatype;
global $$thisfieldnull;
global $$thisdefault;
global $$thisdatalength;
global $$thisdataunsigned;
global $$thisdatazerofill;
global $$thisdatadecimals;
global $$thisdatabinary;
global $$thisdataenum;


if( strlen($$thisfieldname) <= 0) {
continue;
};

echo "<input type=\"hidden\" name=\"" . $thisfieldname . "\"
value=\"" . $$thisfieldname . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdatatype . "\"
value=\"" . $$thisdatatype . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisfieldnull . "\"
value=\"" . $$thisfieldnull . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdefault . "\"
value=\"" . $$thisdefault . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdatalength . "\"
value=\"" . $$thisdatalength . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdataunsigned . "\"
value=\"" . $$thisdataunsigned . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdatazerofill. "\"
value=\"" . $$thisdatazerofill . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdatadecimals . "\"
value=\"" . $$thisdatadecimals . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdatabinary . "\"
value=\"" . $$thisdatabinary . "\">\n";
echo "<input type=\"hidden\" name=\"" . $thisdataenum . "\"
value=\"" . $$thisdataenum . "\">\n";


/* Set our indeces */
echo "<tr>";
echo "<td>" . $$thisfieldname . "</td>";
echo "<td>" . $$thisdatatype . "</td>";

if($primary_key == $i) {
echo "<td></td>";
echo "<td></td>";
echo "<td>Primary Key</td>";
echo "</tr>\n";
continue;
};
echo "<td><input type=\"radio\" name=\"fieldindex_$i\" value=
\"none\" checked></td>";
echo "<td><input type=\"radio\" name=\"fieldindex_$i\" value=
\"indexed\"></td>";
if( $$thisfieldnull != "on") {
echo "<td><input type=\"radio\" name=\"fieldindex_$i\"
value=\"unique\"></td>";
};
echo "</tr>";





};

echo "</table>\n";
echo "<input type=\"submit\">";
echo "</form>";
};
















/*
* Make sure this is the SQL we want.
*/
Function InsertTableUI_4()
{
global $database;
global $tablename;
global $primary_key;

for($i = 0; $i < 15; $i++) {

$thisfieldname = "fieldname_" . $i;
$thisdatatype = "datatype_" . $i;
$thisfieldnull = "allownull_" . $i;
$thisdefault = "default_" . $i;
$thisdatalength = "datalength_" . $i;
$thisdataunsigned = "dataunsigned_" . $i;
$thisdatazerofill = "datazerofill_" . $i;
$thisdatadecimals = "datadecimals_" . $i;
$thisdatabinary = "databinary_" . $i;
$thisdataenum = "dataenum_" . $i;
$thisfieldindex = "fieldindex_" . $i;

global $$thisfieldname;
global $$thisdatatype;
global $$thisfieldnull;
global $$thisdefault;
global $$thisdatalength;
global $$thisdataunsigned;
global $$thisdatazerofill;
global $$thisdatadecimals;
global $$thisdatabinary;
global $$thisdataenum;
global $$thisfieldindex;


/* Column Name */
if( strlen($$thisfieldname) <= 0) {
continue;
} else {
$fields = $fields . $$thisfieldname;
};

/* Column Type */
$fields = $fields . " " . $$thisdatatype;


/* Integer */
if( $$thisdatatype == "TinyInt" ||
$$thisdatatype == "SmallInt" ||
$$thisdatatype == "MediumInt" ||
$$thisdatatype == "Int" ||
$$thisdatatype == "Integer" ||
$$thisdatatype == "BigInt") {


if( $$thisdataunsigned == "on" ) {
$fields = $fields . " UNSIGNED";
};
if( $$thisdatazerofill == "on" ) {
$fields = $fields . " ZEROFILL";
};

};


/* Floating Points */
if( $$thisdatatype == "Float" ||
$$thisdatatype == "Double" ||
$$thisdatatype == "Double Precision" ||
$$thisdatatype == "Real" ||
$$thisdatatype == "Decimal" ||
$$thisdatatype == "Numeric" ) {
$fields = $fields . "(" . $$thisdatalength . "," .
$$thisdatadecimals . ")";

};


/* Timestamp */
if( $$thisdatatype == "Timestamp") {
/* Do nothing */
};


/* Chars */
if( $$thisdatatype == "Char" ||
$$thisdatatype == "VarChar") {

$fields = $fields . "(" . $$thisdatalength . ")";
if($$thisdatabinary == "on") {
$fields = $fields . " BINARY";
};
};


/* Enum / Set */
if( $$thisdatatype == "Enum" ||
$$thisdatatype == "Set") {
$fields = $fields . "(" . $$thisdataenum . ")";
};



/* Allow Nulls? */
if( $primary_key == $i) {
/* Do nothing */
} else if( $$thisfieldnull == "on") {
$fields = $fields . " NULL";
} else {
$fields = $fields . " NOT NULL";
};

/* Default Value */
if( strlen($$thisdefault) > 0 ) {
$fields = $fields . " DEFAULT " . $$thisdefault;
};

/* Auto Increment */


$fields = $fields . ",";


/* Indexed? */
if( $$thisfieldindex == "indexed") {
$fields = $fields . " INDEX " . $$thisfieldname . "(" .
$$thisfieldname . "),";
} else if ( $$thisfieldindex == "unique") {
$fields = $fields . " UNIQUE " . $$thisfieldname . "("
. $$thisfieldname . "),";
} else if ( $primary_key == $i) {
$fields = $fields . " PRIMARY KEY " . "(" .
$$thisfieldname . "),";
}


};

/* Actually create our SQL here */
$fields = substr($fields, 0, strlen($fields) - 1);
$sql = "CREATE TABLE $tablename";
$sql = $sql . "(" . $fields . ")";
echo "<form action=\"mysql.phtml\" method=\"post\">";
echo "<h3> Create Table '$tablename' in Database '$database'?</h3>";
echo "<input type=\"hidden\" name=\"formaction\" value=\"InsertTable\">
\n";
echo "<input type=\"hidden\" name=\"database\" value=\"$database\">\n";
echo "SQL:";
echo "<textarea name=\"SQL\" cols=\"90\" rows=\"10\" wrap=\"soft\">
$sql</textarea>";
echo "<input type=\"submit\">";
echo "</form>";
};




/*
* Actually Create table here.
*/
Function InsertTable()
{
echo "Save Table here.";

};




/*
* ListData -
* Creates a table listing data selected in "sql".
* Parameters:
* $formaction - What URL to go to when "$clickable" field is clicked.
* $clickable - Name of the field which should be clickable.
* $keys -
* $sql - SQL statement, excluding any "ORDER BY" parts.
* $orderbyparameter - "ORDER BY" part of SQL.
* $sortorder - Initial order which data should be sorted in. (asc or
desc).
*/
Function ListData($formaction,$clickable,$keys,$sql,$orderbyparameter,
$sortorder = "asc") {

global $sqlorderby;
global $SCRIPT_NAME;
global $sqlsortorder;
global $database;



/* Figure out our sort order */
if ($sqlsortorder == "asc") {
$sqlsortorder = "desc";
} elseif ($sqlsortorder == "desc") {
$sqlsortorder = "asc";
} else {
$sqlsortorder = $sortorder;
}


/* Figure out what to sort by */
if(IsSet($sqlorderby)) {
$ordersql = $sql . " order by " . $sqlorderby . " " .
$sqlsortorder;
} else {
$ordersql = $sql . " order by " . $orderbyparameter . " " .
$sqlsortorder;
}


/* Get some stats about this recordset */
echo "SQL:" . $sql . "<br>\n";
$recordset = mysql($database,$sql);
$fieldcount = mysql_numfields($recordset);
$rowcount = mysql_numrows($recordset);
echo "<table border>\n";

/* Print column headers */
echo "<tr valign=\"baseline\">";
$j = 0;
while( $j < $fieldcount) {
$currentfield = mysql_fieldname($recordset, $j);
if(isset($keys[$currentfield])) {
/* Skip it */
} else {
echo "<td><h4>";
echo "<a href=\"$SCRIPT_NAME?sqlorderby=
$currentfield&sqlsortorder=" . $sqlsortorder . "\">" . $currentfield . "</a>";
echo "</h4></td>";
}
$j++;
}
echo "</tr>\n";





/* Print column data */
$i = 0;
while( $i < $rowcount) {

/* Oscillate row color */
if( $rowcolor == "#ffffff" ) {
$rowcolor = "#cccccc";
} else {
$rowcolor = "#ffffff";
};


/* Print column data */
echo "<tr bgcolor=\"$rowcolor\" valign=\"baseline\">";
$j = 0;
while( $j < $fieldcount ) {


$currentfield = mysql_fieldname($recordset, $j);
$currentval = mysql_result($recordset, $i,
$currentfield);
if( $currentval == "") {
$currentval = "-";
};
if(isset($keys[$currentfield]) > 0) {
/* Skip it */
} elseif($currentfield == $clickable) {

/* Print out all of our keys */
$k=0;
Reset($keys);
echo "<td><a href=\"$formaction?";

$keyname = key($keys);
$keyval = mysql_result($recordset,$i,$keyname);
echo $keyname . "=" . $keyval;
Next($keys);
$k++;
while ( $k < count($keys)) {
$keyname = key($keys);
$keyval = mysql_result($recordset,$i,
$keyname);
echo "&" . $keyname . "=" . $keyval;
Next($keys);
$k++;
}
echo "\"> $currentval </a></td>";
} else {
echo "<td> $currentval </td>";
}

$j++;
}
echo "</tr>\n";
$i++;
}
echo "</table>\n";
echo "</form>\n";
}




Function AlterTable_SaveState()
{
/*
* AlterTableUI_1
*/
global $database;
global $drop_field;

echo "<input type=\"hidden\" name=\"database\" value=\"" . $database .
"\">\n";
echo "<input type=\"hidden\" name=\"drop_field\" value=\"" .
$drop_field . "\">\n";

if($formaction == "AlterTableUI_1") {
return;
};


/*
* AlterTableUI_2
*/
global $tablename;
echo "<input type=\"hidden\" name=\"tablename\" value=\"" . $tablename.
"\">\n";

if($formaction == "AlterTableUI_2") {
return;
};


/*
* AlterTableUI_3
*/
if($formaction == "AlterTableUI_3") {
return;
};


/*
* AlterTableUI_4
*/
if($formaction == "AlterTableUI_4") {
return;
};
















};



/*
* Which table to alter?
*/
Function AlterTableUI_1()
{
global $database;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"AlterTableUI_2
\">\n";
echo "<h3> Which table do you want to alter?</h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";


/* Pick from all tables */
$recordset = mysql_listtables($database);
$rowcount = mysql_NumRows($recordset);
echo "<select name=\"tablename\">\n";
for($i = 0; $i < $rowcount ; $i++) {
echo "<option>" . mysql_tablename($recordset,$i);
};
echo "</select>";


echo "</form>\n";
};




/*
* What to do to this table.
*/
Function AlterTableUI_2()
{
global $tablename;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"AlterTableUI_3
\">\n";
echo "<h3> How do you want to Alter '" . $tablename . "'?</h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";


echo "<select name=\"alter_type\">\n";
echo "<option>Add Column";
echo "<option>Add Index or Key";
echo "<option>Add Unique Index or Key";
echo "<option>Change a Column Definition";
echo "<option>Delete a Column";
echo "<option>Delete the Primary Key";
echo "<option>Delete an Index";
echo "<option>Rename this Table";
echo "</select>\n";


echo "</form>\n";
};








/*
* Rename Table
*/
Function RenameTableUI_1()
{
global $tablename;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"RenameTableUI_2
\">\n";
echo "<h3> Rename Table </h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";

echo "Rename " . $tablename . " to:";
echo "<input name=\"newtablename\" value=\"" . $tablename . "\">\n";



echo "</form>\n";
};



/*
* Rename Table (Confirm)
*/
Function RenameTableUI_2()
{
global $tablename;
global $newtablename;

$newtablename = strtr($newtablename, " ", "_");
echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"RenameTableUI_2
\">\n";
echo "<h3> Rename '" . $tablename . "' to '" . $newtablename . "'?</h3>
\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";

$sql = "ALTER TABLE " . $tablename . " RENAME AS " . $newtablename;


echo "<textarea name=\"sql\" rows=\"10\" cols=\"90\" >" . $sql .
"</textarea>\n";




echo "</form>\n";
};



/*
* Delete primary key from table.
*/
Function DropPrimaryKey()
{
global $tablename;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"RenameTableUI_2
\">\n";
echo "<h3> Delete Primary Key From '" . $tablename . "?</h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";

$sql = "ALTER TABLE " . $tablename . " DROP PRIMARY KEY";

echo "<textarea name=\"sql\" rows=\"10\" cols=\"90\" >" . $sql .
"</textarea>\n";
echo "</form>\n";
};




/*
* Delete a column.
*/
Function DropColumnUI_1()
{
global $database;
global $tablename;

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"DropColumnUI_2
\">\n";
echo "<h3> Delete which Column From '" . $tablename . "?</h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";

/* Create a list of possible fields. */
echo "<select name=\"drop_field\">\n";
$tablecount = count($querytables);

$recordset = mysql_listfields($database, $tablename);
$rowcount = mysql_numfields($recordset);
for($i = 0; $i < $rowcount; $i++) {
echo "<option>" . mysql_fieldname($recordset, $i);
};
echo "</select>\n";


echo "</form>\n";
};


/*
* Drop a column (Confirm)
*/
Function DropColumnUI_2()
{
global $tablename;
global $drop_field;


echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<input type=\"hidden\" name=\"formaction\" value=\"RenameTableUI_2
\">\n";
echo "<h3> Delete Column '" . $drop_field . "' From '" . $tablename .
"'?</h3>\n";
echo "<input type=\"submit\">\n";
AlterTable_SaveState();
echo "<hr>\n";

$sql = "ALTER TABLE " . $tablename . " DROP COLUMN " . $drop_field;

echo "<textarea name=\"sql\" rows=\"10\" cols=\"90\" >" . $sql .
"</textarea>\n";
echo "</form>\n";
};








/*
* All of our options.
*/
Function Index()
{

echo "<form method=\"post\" action=\"mysql.phtml\">\n";
echo "<h3> MySQL Webmin</h3>\n";
echo "Mike Kachline (<a href=
\"mailto:kachline@cc.gatech.edu\">kachline@cc.gatech.edu</a>)<br>\n";
echo "<input type=\"submit\">";
echo "<hr>\n";


echo "<h4> Perform Which Action? </h4>\n";
echo "<select name=\"formaction\">\n";
echo "<option value=\"InsertDatabaseUI_1\">Create New Database";
echo "<option value=\"InsertTableUI_1\">Create New Table";
echo "<option value=\"AlterTableUI_1\">Alter An Existing Table's
Definition";
echo "<option value=\"QueryTablesUI_1\">Create New Query";
echo "</select>\n";

echo "<h4> Use Which Database? </h4>";
echo "Database:<select name=\"database\">\n";
$recordset = mysql_ListDBs();
for($i = 0; $i < mysql_NumRows($recordset); $i++) {
echo "<option>" . mysql_DBName($recordset, $i);
};
echo "</select><br>\n";
echo "Username:<input name=\"MysqlUsername\"><br>\n";
echo "Password:<input name=\"MysqlPassword\" type=\"password\"><br>\n";




echo "</form>\n";
};





/*
* Figure out where to go from here.
*
*
*/



/* Create Table */
if( $formaction == "InsertTable") {
InsertTable();
} else if ($formaction == "InsertTableUI_1") {
InsertTableUI_1();
} else if ($formaction == "InsertTableUI_2") {
InsertTableUI_2();
} else if ($formaction == "InsertTableUI_3") {
InsertTableUI_3();
} else if ($formaction == "InsertTableUI_4") {
InsertTableUI_4();

/* Create Database */
} else if ($formaction == "InsertDatabaseUI_1") {
InsertDatabaseUI_1();
} else if ($formaction == "InsertDatabaseUI_2") {
InsertDatabaseUI_2();
} else if ($formaction == "InsertDatabase") {
InsertDatabase();


/* Query Tables */
} else if ($formaction == "QueryTablesUI_1") {
QueryTablesUI_1();
} else if ($formaction == "QueryTablesUI_2") {
QueryTablesUI_2();
} else if ($formaction == "QueryTablesUI_3") {
QueryTablesUI_3();
} else if ($formaction == "QueryTablesUI_4") {
QueryTablesUI_4();
} else if ($formaction == "QueryTablesUI_5") {
QueryTablesUI_5();
} else if ($formaction == "QueryTablesUI_6") {
QueryTablesUI_6();
} else if ($formaction == "QueryTablesUI_7") {
QueryTablesUI_7();
} else if ($formaction == "QueryTablesUI_8") {
QueryTablesUI_8();
} else if ($formaction == "QueryTables") {
QueryTables();


/* Alter Tables */
} else if ($formaction == "AlterTableUI_1") {
AlterTableUI_1();
} else if ($formaction == "AlterTableUI_2") {
AlterTableUI_2();
} else if ($formaction == "AlterTableUI_3") {
if($alter_type == "Rename this Table") {
RenameTableUI_1();
} else if($alter_type == "Delete the Primary Key") {
DropPrimaryKey();
} else if($alter_type == "Delete a Column") {
DropColumnUI_1();


} else {
AlterTableUI_1();
};




} else if ($formaction == "RenameTableUI_2") {
RenameTableUI_2();
} else if ($formaction == "DropColumnUI_2") {
DropColumnUI_2();

} else if ($formaction == "AlterTableUI_4") {
AlterTableUI_4();
} else if ($formaction == "AlterTableUI_5") {
AlterTableUI_5();
} else if ($formaction == "AlterTableUI_6") {
AlterTableUI_6();
} else if ($formaction == "AlterTableUI_7") {
AlterTableUI_7();
} else if ($formaction == "AlterTableUI_8") {
AlterTableUI_8();
} else if ($formaction == "AlterTable") {
AlterTable();


/* Default page */
} else {
Index();
};





?>
</html>



bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager
Categories : MySQL, PHP, MySQL, Complete Programs, Databases
This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
Example voting script. Lets people enter suggestions and vote for existing ones.
Categories : MySQL, PHP, Cookies, Complete Programs, Databases
This is a very simple BBS that uses MySQL
Categories : MySQL, Databases, Complete Programs, PHP
Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs.
Categories : Databases, PHP, MySQL, Complete Programs
phpAds, a complete banner and ad management system with detailled tracking and stats.
Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases
phpEasySQL - Easily connect to your MySQL database with just 1 php file and 3 easy steps!
Categories : Databases, PHP, MySQL, General SQL
free, search engine, indexing, system, information, web, ftp, http, free, software, cgi, php, MySQL, database, php3, FreeBSD, Linux, Unix, UdmSearch
Categories : MySQL, Complete Programs, PHP, Databases, Search
This function will populate the options in a drop down HTML select list in a form from a database query.
Categories : MySQL, General SQL, PHP, HTML and PHP, Databases
complete, simple, working example of a login screen/system using php functions, cookies, and a mysql database for begginers.
Categories : Authentication, Complete Programs, PHP, MySQL, Databases
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
Shopping Cart e-Commerce Solution
Categories : Complete Programs, PHP, MySQL, Databases
phpMyAdmin is intended to handle the adminstration of MySQL over the web.
Categories : Databases, MySQL, Complete Programs, PHP
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases