Jump to content

Making a list into a table


iRush

Recommended Posts

Now that i have my code that shows my list on the localhost I want to try and put this into a table and beable to add a delete from the table. Here's my code any help would be much appreciated.

 

<?PHP
// please add login and pass here//
$host	= "localhost";
$login 	= "root" ;
$pass 	= "";

mysql_connect("$host","$login","$pass") OR DIE
        ("There is a problem with the system.  Please notify your system administrator." .mysql_error());

//Seems in this case we can use a general call
$connection = mysql_connect("$host","$login","$pass") 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++;
    }


//Start Create DB//
IF (isset($_POST['result'])){
$database=$_POST['database'];
$sql="CREATE DATABASE $database ";
$result = mysql_query($sql,$connection) or die(mysql_error());
echo "Database $database has been added";

}

IF (isset($_POST['delete'])){
$db=$_POST['db'];
$query=mysql_query("DROP DATABASE $db");
echo "Database $db has been deleted";

}
?>
<html>
<head>
<title>MySQL Databases</title>
</head>
<body>
<p><strong>Databases on localhost</strong>:</p>
<? echo "$db_list"; ?>


<?PHP
//print_r($_POST);
?>
<form action="pretask.php" method="post">
<select name="db">
<?PHP
$db_list = mysql_list_dbs($connection);
while ($row = mysql_fetch_object($db_list)) {
//Here you are listing anything that should not be included
if ($row->Database!="information_schema" && $row->Database!="mysql" && $row->Database!="phpmyadmin"){
echo "<option value=\"".$row->Database."\">".$row->Database."</option>";

 }

}

?>
</select>
<input type="submit" name="delete" value="Delete"/>
</form>
<form action="pretask.php" method="post">
Create Database <input type="text" name="database" />
<input type="submit" name="result" value="Create" />
</form>
</body>

Link to comment
https://forums.phpfreaks.com/topic/249499-making-a-list-into-a-table/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.