<?php 

require "top.php"; 
require "dbconnect.php";

if(isset($_GET['type']) && $_GET['type']!=''){
    $type = $_GET['type'];

    if($type=='delete'){ 
        $id = $_GET['id'];
        $delete_sql = "delete from tilting where id='$id'";
        mysqli_query($con,$delete_sql);
    }
}

if(isset($_POST['submit'])){
    $title = $_POST['title'];
    $subtitle1 = $_POST['subtitle1'];
    $desc = $_POST['description'];
    $desc1 = $_POST['description1'];
    
    $sql = "insert into tilting(title,subtitle1,description,description1) values('$title','$subtitle1','$desc','$desc1')";
    $res = mysqli_query($con,$sql);
}

?>

<div class="container gap my-4">
    <h4>Tilting Form</h4>
    <form method="post">
        <div class="form-group">
            <label>Title</label>
            <input type="text" name="title" class="form-control">
        </div>
        <div class="form-group">
            <label>Description</label>
            <textarea name="description" rows="5" class=form-control></textarea>
        </div>
        <div class="form-group">
            <label>Sub Title1</label>
            <input type="text" name="subtitle1" class="form-control">
        </div>
        <div class="form-group">
            <label>Description1</label>
            <textarea name="description1" rows="5" class=form-control></textarea>
        </div>
        <div class="form-group">
            <button class="btn btn-primary" name="submit">Submit</button>
        </div>
    </form>
    <div class="row">
        <table class="table table-bordered">
            <thead class="bg-info">
                <tr>
                    <th>Title</th>
                    <th>Description</th>
                    <th>Sub Title1</th>
                    <th>Description1</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody>
                <?php
                $res = mysqli_query($con,"select * from tilting");
                while($row = mysqli_fetch_assoc($res)){
                ?>
                <tr>
                    <td><?php echo $row['title'] ?></td>
                    <td><?php echo $row['description'] ?></td>
                    <td><?php echo $row['subtitle1'] ?></td>
                    <td><?php echo $row['description1'] ?></td>
                    <td><?php 
                    echo "<a class='btn btn-danger' href='?type=delete&id=".$row['id']."'>Delete</a>";
                    ?></td>
                </tr>
                <?php } ?>
            </tbody>
        </table>
    </div>
</div>


<?php require "footer.php"; ?>