<?php
$name = $_POST["name"];
$pass = $_POST["pass"];

$servername = "localhost";
$username = "mtplusteam_mtplusteam";
$password = "R{Kfeq+_qICNX=DB";
$dbname = "mtplusteam_server";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    echo "error-admin";
    exit;
}

$sql = "SELECT * FROM dhtml WHERE name='$name'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $pass2 = $row["pass"];
        $username = $row["username"];

        if ($pass2 == $pass) {
            $jsonFile = $name . '.html';

            if (file_exists($jsonFile)) {
                unlink($jsonFile);
            }


            $deleteSql = "DELETE FROM dhtml WHERE name='$name'";
            if ($conn->query($deleteSql) === TRUE) {
                echo "ok";
            } else {
                echo "error-delete-db";
            }
        } else {
            echo "error-db";
        }
    }
} else {
    echo "error-user";
}

$conn->close();
?>