<?php if(isset($_POST['add'])) { $name = mysqli_real_escape_string($cn,$_POST['name']); $sort_order = $_POST['sort_order']; $sql = mysqli_query($cn, "select * from `tbl_polish` where `name`='$name'"); if(mysqli_num_rows($sql)>0) { echo '<div class="alert alert-danger"><strong>Danger!</strong> Polish already exists.</div>'; } else { $sqlSubject = mysqli_query ($cn, "insert into `tbl_polish` set `name`='$name', sort_order='$sort_order'"); if ($sqlSubject){ echo '<div class="alert alert-success"><strong>Success!</strong> Polish Added Successfully.</div>'; } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> Polish Not Added. Try Again.</div>'; } } } if(isset($_POST['edit'])) { $id = $_POST['id']; $name = $_POST['name']; $sort_order = $_POST['sort_order']; $sqlSubject = mysqli_query ($cn,"update `tbl_polish` SET `name`='$name', `sort_order`='$sort_order' where `id`='$id'"); if($sqlSubject) { echo '<div class="alert alert-success"><strong>Success!</strong> Polish Update Successfully.</div>'; } else { echo '<div class="alert alert-success"><strong>Warning!</strong> Polish Updated try again.</div>'; } } if(isset($_GET['edit_id'])) { $id = $_GET['edit_id']; $sql = mysqli_query($cn, "select * from `tbl_polish` where id='$id'"); $sqlData = mysqli_fetch_array ($sql); } ?> <div class="card"> <div class="card-body"> <h4 class="card-title">Polish</h4> <form class="forms-sample" method="post" enctype="multipart/form-data"> <div class="row"> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputName1">Name</label> <input type="hidden" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['id'];}?>" name="id"> <input type="text" class="form-control" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['name'];}?>" name="name" placeholder="Name" autocomplete="off" required> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputName1">Sort Order</label> <input type="text" class="form-control" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['sort_order'];}?>" name="sort_order" placeholder="Sort Order" autocomplete="off" required> </div> </div> </div> <button type="submit" class="btn btn-success mr-2" name="<?php if(isset($_GET['edit_id'])) {echo "edit";}else{ echo "add";}?>">Submit</button> </form> </div> </div> <br><br> <div class="col-lg-12 grid-margin stretch-card"> <div class="card"> <div class="card-body"> <h4 class="card-title">Polish List</h4> <div class="table-responsive"> <table class="table table-striped" id="example"> <thead> <tr> <th width="5%">S.No.</th> <th width="75%">Name</th> <th width="10%">Sort Order</th> <th width="10%">Action</th> </tr> </thead> <tbody> <?php $i = 1; $sqlEmployee = mysqli_query($cn, "select * from `tbl_polish` order by `sort_order`"); while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee)){?> <tr> <td><?php echo $i++;?></td> <td><?php echo $sqlEmployeeData['name'];?></td> <td><?php echo $sqlEmployeeData['sort_order'];?></td> <td><a href="home.php?pages=polish&edit_id=<?php echo $sqlEmployeeData['id'];?>">Edit</a></td> </tr> <?php }?> </tbody> </table> </div> </div> </div> </div>