0

I recently had an issue that was doing my head in and was quickly and easily fixed simply asking you guys here. Was hoping someone could help me even further as I have no clue where to start.. but basically I have a page that displays a table of servers that we run on a linux server.

The delete.php code that I will post below, removes the row from the table/database so it no longer shows up on the server page, so it can be reinstalled. The problem is that the files/folders also remain on the server. Ideally, Id want this script to also delete these too. The folder name is the same as the server name.

I have SSH access as thats how the server files are installed via the install page, but is there a way I can add to this delete.php and also delete the files easily?

    <?php
// Your database info
$db_host = 'localhost';
$db_user = 'user';
$db_pass = 'pass';
$db_name = 'database';

if (!isset($_GET['id']))
{
    echo 'No ID was given...';
    exit;
}

$con = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($con->connect_error)
{
    die('Connect Error (' . $con->connect_errno . ') ' . $con->connect_error);
}
$sql = "DELETE FROM installed_servers WHERE `index` = ?";

if (!$result = $con->prepare($sql))
{
    die('Query failed: (' . $con->errno . ') ' . $con->error);
}

if (!$result->bind_param('i', $_GET['id']))
{
    die('Binding parameters failed: (' . $result->errno . ') ' . $result->error);
}

if (!$result->execute())
{
    die('Execute failed: (' . $result->errno . ') ' . $result->error);
}

if ($result->affected_rows > 0)
{
    echo "The ID was deleted with success.";

}
else
{
    echo "Couldn't delete the index.";
}
$result->close();
$con->close();
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126

0 Answers0