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

include("common_db.php");
include("functions.php");

dbconnect($host, $username, $password);
$strings = loadStrings($lang, 'TRENAME');
headers();
html();
head($strings['TR_TITLE'], array('xhr/create-xhr.php?target=\'xhr/get-data.php?action=tl-ops\'%2BString.fromCharCode(38)%2B\'db=\'%2Bindb&amp;caller=reloadTables&amp;tid=tbl&amp;tfunc=clearElem(\'tbl\');'));
menu();
navpane();
echo('<div id="mainpane">');

if(isset($_REQUEST['database'])) {
	$db = $_REQUEST['database'];
} else {
	if($_SESSION['current_db']!='') {
		$db = $_SESSION['current_db'];
	} else {	//don't know which db
		printRequestForm('tblrename.php');
	}
}

if(isset($_REQUEST['table'])) {
	$table = $_REQUEST['table'];
} else {
	printRequestForm('tblrename.php',$db);
}

if(isset($_REQUEST['new_table_name'])) {
	$new_table_name = $_REQUEST['new_table_name'];
} else {
	$new_table_name = '';
}


if($new_table_name != '')
{
   mysql_select_db($db) or die("couldn't select database $db");

   $query = "RENAME TABLE `$table` TO `$new_table_name`";

   if(mysql_query($query)) {
      $tbl_renamed = true;
   } else {
      $tbl_renamed = false;
      $rename_error = mysql_error();
   }
}


if($new_table_name == '')
{
	echo '<p class="alert">' . $strings['TR_WARNING'] . '</p>';
	echo '<form method="POST" action="tblrename.php" class="standalone lblock">';
	echo '<label for="new_table_name">';
	printf($strings['TR_NNHELP'],$table);
	echo '<input type="text" name="new_table_name" /></label>';
	echo '<input type="hidden" name="table" value="' . $table . '" />';
	echo '<input type="hidden" name="database" value="' . $db . '" />';
	echo '<input type="submit" value="' . $strings['TR_SUBMIT'] . '" />';
	echo '</form>';
}
else {
   if($tbl_renamed) {
	printf("<p>" . $strings['TR_SUCCESS'] . "</p>", $table, $new_table_name);
   } else {
	printError(sprintf($strings['TR_NNFAILED'], $rename_error), mysql_error());
   }
}

echo('</div>');
endhtml();
?>
Return current item: HypatiaDB