<!DOCTYPE html>

<html lang="en">

<?php
    if($_SERVER["REQUEST_METHOD"] == "POST"){
        $price = ($_POST["price"]);
        $bedrooms = ($_POST["bedrooms"]);
        $bathrooms = ($_POST["bathrooms"]);
        $home_footage = ($_POST["home_footage"]);
        $land_footage = ($_POST["land_footage"]);
        $address = ($_POST["address"]);
        $city = ($_POST["city"]);
        $state = ($_POST["state"]);
        $type = ($_POST["type"]);
        $fees = ($_POST["fees"]);
        $img = ($_POST["img"]);
        $status = ($_POST["status"]);
        $success = true;
    }

    if($success){
        require_once("connect-db.php");

        $sql = "insert into house(price, bedrooms, bathrooms, home_footage, land_footage, address, city, state, type, fees, img, status) values (:price, :bedrooms, :bathrooms, :home_footage, :land_footage, :address, :city, :state, :type, :fees, :img, :status)";
                
        $statement = $db->prepare($sql);
        
        $statement->bindValue(":price", $price);
        $statement->bindValue(":bedrooms", $bedrooms);
        $statement->bindValue(":bathrooms", $bathrooms);
        $statement->bindValue(":home_footage", $home_footage);
        $statement->bindValue(":land_footage", $land_footage);
        $statement->bindValue(":address", $address);
        $statement->bindValue(":city", $city);
        $statement->bindValue(":state", $state);
        $statement->bindValue(":type", $type);
        $statement->bindValue(":fees", $fees);
        $statement->bindValue(":img", $img);
        $statement->bindValue(":status", $status);
        
        if($statement->execute()){
            $statement->closeCursor();
        }
    }
?>
<script>
    setTimeout(function(){
        window.location.href = "home-list.php";
    }, 5000);
</script>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>D&B Realty</title>
	<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>

<body>
    <div class="container">
        <?php include("header_nav.html");?>
        <main>
            <h4>Home successfully added to database. Redirecting in 5 seconds.</h4>
        </main>
        <?php include("footer.html");?>
    </div>
</body>

</html>