<?php

    if(isset($_POST) && $_POST['title']){
        $wpdb->update( 'slider', array( 'title' => $_POST['title'],'description' => $_POST['description'],'image' => $_POST['image']),array('id'=>$_GET['id']));
        
        echo "<script>window.location.href='?page=allslider';</script>";
    }

    $data = $wpdb -> get_results("SELECT * FROM `slider` WHERE id = '".$_GET['id']."' ORDER BY id"); 

    foreach ($data as $row) {

?>
<form action="" method="post">
    <div class="container mt-5">
        <div class="row">
            <div class="col-lg-8 col-12">
                <div class="mb-3">
                    <label for="formGroupExampleInput" class="form-label"><h5>Edit Slider</h5></label>
                    <input type="text" class="form-control form-control-lg" id="formGroupExampleInput" name="title" value="<?php echo ''.$row->title.''; ?>">
                </div>
                <div class="mb-3">
                    <label for="formGroupExampleInput2" class="form-label"><h5>Description</h5></label>
                    <input type="text" class="form-control form-control-lg" id="formGroupExampleInput2" name="description" value="<?php echo ''.$row->description.''; ?>">
                </div>
                <div class="mb-3">
                    <label for="formGroupExampleInput2" class="form-label"><h5>Image File</h5></label>
                    <input type="text" name="image" value="<?php echo ''.$row->image.''; ?>" id="getSlider" hidden>
                    <img src="<?php echo ''.$row->image.''; ?>" class="d-block w-100" id="bttnImage" height="400px">
                </div>
                <div class="mb-3">
                    <button type="submit" class="btn btn-primary mb-3">Save</button>
                </div>
            </div>
        </div>
    </div>
</form>
<?php } ?>