<?php
$user = $_POST["username"];
$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";
}

$user = mysqli_real_escape_string($conn, $user);
$pass = mysqli_real_escape_string($conn, $pass);
$sql = "SELECT pass FROM login WHERE username='$user'";

$result = $conn->query($sql);

if($result->num_rows > 0){
    $row = $result->fetch_assoc();

    $pass2 = $row["pass"];
        
    if($pass2 == $pass){
        $json = array(); 

        $sql = "SELECT * FROM dhtml WHERE username='$user'";

        $result = $conn->query($sql);

        if($result->num_rows > 0){
            while($row = $result->fetch_assoc()){
                array_push($json, $row);
            }

            echo json_encode($json);
        }
        else{
            echo "error-user";
        }
    }
    else{
        echo "error-user";
    }
}
else{
    echo "error-user";
}

$conn->close();
?>