0

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)

?>
3
Contributors
3
Replies
12
Views
6 Years
Discussion Span
Last Post by ajbest
0

Please manage your code nicely before other people can help on your code,seperate the the code with the file name as well!!!

0

agreed... Please at least separate the pages into different code blocks.

Regardless, looks like you are missing the name attribute for your delete dropdown list. This would be required in order to pass the desired delete value onto the page that processes deleting.

Also, you need to work on the formatting of your select input all together. Check W3C for an example of the code for a select menu. OR even DW will create one for you that you can then follow along with.

0
<select name="table_to_delete">
   <option value="table1">table1</option>
   <option value="table2">table2</option>
   <option value="table3">table3</option>
</select>

regardless of how you get there. this is what your select menu needs to look like in the browser.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.