Hey guys i have a code here that allows me to add any database to the existing database that i have already. I can do that fin by using a text field and submit button for that. Now the harder part for me is trying to delete an existing field by using the drop down list that shows all the databases and choosing one and then hitting a "submit" button do delete the database. This is my code as of right now but my delete part is all messed up..any help would be greatly appreciated.
<?
$connection = @mysql_connect("localhost", "root", "") or die(mysql_error());;
$dbs = @mysql_list_dbs($connection)or die(mysql_error());
$db_list="<ul>";
$i =0;
while ($i < mysql_num_rows($dbs)){
$db_names[$i] = mysql_tablename($dbs,$i);
$db_list .="<li>$db_names[$i]";
$i++;
}
$db_list .="</ul>";
?>
<HTML>
<HEAD>
<TITLE>MySQL Databases</TITLE>
</HEAD>
<P><strong>Databases on localhost</strong>:</p>
<? echo "$db_list"; ?>
</BODY>
</HTML>
<form action="pretask.php" method="post">
Create Database <input type="text" name="database" />
<input type="submit" name="result" value="Create" />
</form>
</body>
</html>
<?php
$database=$_POST['database'];
$connection = @mysql_connect("localhost","root","") or die(mysql_error());
$sql="CREATE DATABASE $database ";
$result = @mysql_query($sql,$connection) or die(mysql_error());
if (isset($_POST['result']))
{
Results:
echo "Database $database has been added";
}
mysql_close($connection)
?>
<html>
<body>
<form action="pretask.php" method="post">
<select>
<option>$db_list</option>
</select>
<input type="submit" name="delete" value="delete"/>
</form>
</body>
</html>
<?php
$delete=$_POST['delete'];
$connection = @mysql_connect("localhost","root","") or die(mysql_error());
$sql="DROP DATABASE $delete";
if (isset($_POST['result']))
{
Result:
echo "Database $delete has been deleted";
}
mysql_close($connection)
?>