<?php if(isset($_POST['add'])) { $name = mysqli_real_escape_string($cn,$_POST['name']); $image = $_FILES['image']['name']; $sort_order = $_POST['sort_order']; $staus = $_POST['status']; $menu_type = $_POST['menu_type']; $slug_url = mysqli_real_escape_string($cn,$_POST['slug_url']); $validation = 1; if(!empty($image)) { $imgExe = explode(".",$image); if($imgExe[1]=='jpg' or $imgExe[1]=='jpeg' or $imgExe[1]=='png') { move_uploaded_file ($_FILES['image']['tmp_name'],'../categorys/'.$image); } else { $error = "Only .jpg, .jpeg, .png Allow."; $validation = 0; } } if($validation==1) { $sql = mysqli_query($cn, "select * from tbl_category where `name`='$name'"); if(mysqli_num_rows($sql)>0) { echo '<div class="alert alert-danger"><strong>Danger!</strong> Category name already exists.</div>'; } else { $sqlSubject=mysqli_query ($cn, "insert into `tbl_category` set `name`='$name', `image`='$image', `sort_order`='$sort_order', `slug_url`='$slug_url', `status`=1, `menu_type`='".$menu_type."'"); if ($sqlSubject) { echo '<div class="alert alert-success"><strong>Success!</strong> Category Added Successfully.</div>'; } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> Category Not Added. Try Again.</div>'; } } } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> '.$error.'</div>'; } } if(isset($_POST['edit'])) { $id = $_POST['id']; $name = $_POST['name']; $image = $_FILES['image']['name']; $sort_order = $_POST['sort_order']; $status = $_POST['status']; $menu_type = $_POST['menu_type']; $slug_url = mysqli_real_escape_string($cn,$_POST['slug_url']); $sql = mysqli_query($cn, "select * from tbl_category where id='$id'"); $sqlData = mysqli_fetch_array($sql); $validation = 1; if(!empty($image)) { $imgExe = explode(".",$image); if($imgExe[1]=='jpg' or $imgExe[1]=='jpeg' or $imgExe[1]=='png') { move_uploaded_file ($_FILES['image']['tmp_name'],'../categorys/'.$image); } else { $error = "Only .jpg, .jpeg, .png Allow."; $validation = 0; } } else { $image = $sqlData['image']; } if($validation==1) { $sqlSubject = mysqli_query ($cn,"update tbl_category SET name='$name',image='$image',sort_order='$sort_order',status='$status',slug_url='$slug_url', `menu_type`='".$menu_type."' where `id`='$id'"); if($sqlSubject) { echo '<div class="alert alert-success"><strong>Success!</strong> Category Update Successfully.</div>'; } else { echo '<div class="alert alert-success"><strong>Warrning!</strong> Category Not Updated. Try again.</div>'; } } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> '.$error.'</div>'; } } if(isset($_GET['edit_id'])) { $id = $_GET['edit_id']; $sql = mysqli_query($cn, "select * from tbl_category where id='$id'"); $sqlData = mysqli_fetch_array ($sql); } if(isset($_GET['status'])) { $id = $_GET['status']; $val = $_GET['val']; $sql = mysqli_query($cn, "update tbl_category SET `status`='$val' where id='$id'"); } ?> <div class="card"> <div class="card-body"> <h4 class="card-title">Category</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">Category Name <span style="color:#F00;">*</span></label> <input type="hidden" class="tableName" value="tbl_category"> <input type="hidden" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['id'];}?>" name="id"> <input type="text" class="form-control setslugUrl" 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">Category Image <span style="color:#F00;">*</span></label> <input type="file" class="form-control" name="image" id="fileToUpload" <?php if(isset($_GET['edit_id'])){}else{?> required <?php }?>> <p style="color:red; ">Size must 235X54</p> <?php if(isset($_GET['edit_id'])) {?> <img src="../categorys/<?php echo $sqlData['image'];?>" height="150" width="100"> <?php }?> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputName1">Sort Order <span style="color:#F00;">*</span></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 class="col-md-3"> <div class="form-group"> <label>Status <span style="color:#F00;">*</span></label> <div class="row"> <div class="col-md-4"> <div class="form-radio"> <label class="form-check-label"><input type="radio" class="form-check-input" name="status" id="membershipRadios1" value="1" <?php if(isset($_GET['edit_id'])){ if($sqlData['status']==1){ echo "checked";}}else{ echo "checked";}?>> Yes</label> </div> </div> <div class="col-md-4"> <div class="form-radio"> <label class="form-check-label"><input type="radio" class="form-check-input" name="status" id="membershipRadios2" value="0" <?php if(isset($_GET['edit_id'])){if($sqlData['status']==0){ echo "checked";}}?>> No</label> </div> </div> </div> </div> </div> </div> <div class="row"> <div class="col-md-9"> <div class="form-group"> <label for="exampleInputName1">Slug Url <span style="color:#F00;">*</span></label> <input type="text" class="form-control slugUrl" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['slug_url'];}?>" name="slug_url" placeholder="Slug Url" autocomplete="off" readonly="readonly" required> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputName1">Menu Type <span style="color:#F00;">*</span></label> <select name="menu_type" class="form-control" required> <option value="">Select Type</option> <option value="1" <?php if(isset($_GET['edit_id'])){if($sqlData['menu_type']==1){echo "selected";}}?>>Direct Menu</option> <option value="2" <?php if(isset($_GET['edit_id'])){if($sqlData['menu_type']==2){echo "selected";}}?>>Shop Inner Menu</option> </select> </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> <?php if(isset($_GET['delete_id'])) { $id = $_GET['delete_id']; $sql = mysqli_query($cn, "update `tbl_category` SET `status`=2 where id='$id'"); if($sql) { echo '<div class="alert alert-success"><strong>Success!</strong> Category Deleted Successfully.</div>'; } else { echo "error: " . $sql . "<br>" . mysqli_error($conn); } } ?> <div class="col-lg-12 grid-margin stretch-card"> <div class="card"> <div class="card-body"> <h4 class="card-title">Category List</h4> <div class="table-responsive"> <table class="table table-striped" id="example"> <thead> <tr> <th>Sr.No.</th> <th>Image</th> <th>Category Name</th> <th>Sort Order</th> <th>Status</th> <th>Action</th> </tr> </thead> <tbody> <?php $i = 1; $sqlEmployee = mysqli_query($cn, "select * from `tbl_category` where `status` IN(0,1) order by `sort_order`"); while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee)) {?> <tr> <td><?php echo $i++;?></td> <td><img src="../categorys/<?php echo $sqlEmployeeData['image'];?>" height="150" width="200"></td> <td><?php echo $sqlEmployeeData['name'];?></td> <td><?php echo $sqlEmployeeData['sort_order'];?></td> <td> <?php if($sqlEmployeeData['status']==1){?> <a href="home.php?pages=category&status=<?php echo $sqlEmployeeData['id'];?>&val=0">YES</a> <?php }else{?> <a href="home.php?pages=category&status=<?php echo $sqlEmployeeData['id'];?>&val=1">NO</a> <?php }?> </td> <td><a href="home.php?pages=category&edit_id=<?php echo $sqlEmployeeData['id'];?>">Edit</a> | <a href="home.php?pages=category&delete_id=<?php echo $sqlEmployeeData['id'];?>" onclick="return deleteConfirm();">Delete</a></td> </tr> <?php } ?> </tbody> </table> </div> </div> </div> </div>