Location: PHPKode > projects > HypatiaDB > hypatiadb/dbcreate.php
<?php

/* HypatiaDB - Easy to use web-based database management system. Written primarily in PHP using  * the MySQL database engine.
 * Copyright (C) 2004 Simon D'Alfonso
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


include("common_db.php");
include("functions.php");
dbconnect($host, $username, $password);

$db_name = '';
if(isset($_REQUEST['db_name']) && ($_SESSION['session_user_status'] == 'admin' || $_SESSION['session_user_status'] == 'normal')) {
	//TODO: Validate dbname
	$db_name = mysql_real_escape_string($_REQUEST['db_name']);

	$dbCreateQuery="CREATE DATABASE `$db_name`";
	if(mysql_query($dbCreateQuery))
		$db_created = true;
	else {
		$db_created = false;
		$err = mysql_error();
	}
} else {
	$db_created = false;
}

$strings = loadStrings($lang, 'CDBF');
headers();
html();
head($strings['CDB_TITLE'],array('js/dbcreate.php'));
menu();
navpane();

?>

<div id="mainpane">

<?php

if($db_name == '') {
	echo '<form onsubmit="return validDBName(this);" method="post" action="#" class="standalone">';
	echo '<label for="db_name">' . $strings['CDB_FORM_DBNAME'] . '<input type="text" name="db_name" /></label>';
	echo '<input type="submit" value="' . $strings['CDB_FORM_SUBMIT'] . '" />';
	echo '</form>';
} else { 
	if($db_created)
		printf("<p>$strings[CDB_SUCCESS]</p>", $db_name);
	else
		printError(sprintf($strings['CDBFAILED'], $err));
}


echo('</div>');

endhtml();
?>
Return current item: HypatiaDB