<?php if(isset($_POST['add'])) { $distributor_id = $_POST['distributor_id']; $name = mysqli_real_escape_string($cn,$_POST['name']); $mobile = mysqli_real_escape_string($cn,$_POST['mobile']); $email = mysqli_real_escape_string($cn,$_POST['email']); $gst = $_POST['gst']; $address = mysqli_real_escape_string($cn,$_POST['address']); $sqlSubject = mysqli_query($cn, "insert into `tbl_retailer` set `distributor_id`='$distributor_id', `name`='$name', `mobile`='$mobile', `email`='$email', `gst`='$gst', `address`='$address'"); if ($sqlSubject){ echo '<div class="alert alert-success"><strong>Success!</strong> Retailer Added Successfully.</div>'; } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> Retailer Not Added. Try Again.</div>'; } } if(isset($_POST['edit'])) { $edit_id = $_POST['edit_id']; $distributor_id = $_POST['distributor_id']; $name = mysqli_real_escape_string($cn,$_POST['name']); $mobile = mysqli_real_escape_string($cn,$_POST['mobile']); $email = mysqli_real_escape_string($cn,$_POST['email']); $gst = $_POST['gst']; $address = mysqli_real_escape_string($cn,$_POST['address']); $sqlSubject = mysqli_query($cn, "update `tbl_retailer` set `distributor_id`='$distributor_id', `name`='$name', `mobile`='$mobile', `email`='$email', `gst`='$gst', `address`='$address' where `id`='".$edit_id."'"); if ($sqlSubject){ echo '<div class="alert alert-success"><strong>Success!</strong> Retailer Update Successfully.</div>'; } else { echo '<div class="alert alert-danger"><strong>Danger!</strong> Retailer Update Added. Try Again.</div>'; } } if(isset($_GET['edit_id'])) { $id = $_GET['edit_id']; $sql = mysqli_query($cn, "select * from tbl_retailer where id='$id'"); $sqlData = mysqli_fetch_array ($sql); } if(isset($_GET['delete_id'])) { $id = $_GET['delete_id']; $sql = mysqli_query($cn, "update `tbl_retailer` SET `status`=0 where id='$id'"); echo '<div class="alert alert-danger"><strong>Danger!</strong> Retailer Deleted Successfully.</div>'; } ?> <div class="col-md-12"> <div class="card"> <div class="card-body"> <h4 class="card-title"><?php if(isset($_GET['edit_id'])){ echo "Edit Retailer Registation";}else{ echo "Retailer Registation";}?></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="exampleInputCity1">Distributor Name</label> <select class="form-control" name="distributor_id" required=""> <option value="">Select Distributor</option> <?php $sqlDistributor = mysqli_query($cn, "select * from `tbl_distributor` order by name"); while($sqlDistributorData = mysqli_fetch_array($sqlDistributor)){?> <option value="<?php echo $sqlDistributorData['id'];?>" <?php if(isset($_GET['edit_id'])){ if($sqlData['distributor_id']==$sqlDistributorData['id']){ echo "selected";}}?>><?php echo $sqlDistributorData['name'];?></option> <?php }?> </select> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputCity1">Retailer Name</label> <input type="hidden" name="edit_id" value="<?php if(isset($_GET['edit_id'])) {echo $sqlData['id'];}?>"> <input type="text" class="form-control" name="name" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['name'];}?>" placeholder="Retailer Name" required> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputCity1">Mobile No.</label> <input type="text" class="form-control" name="mobile" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['mobile'];}?>" placeholder="Mobile" required> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputCity1">Email</label> <input type="text" class="form-control" name="email" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['email'];}?>" placeholder="Email" required> </div> </div> <div class="col-md-3"> <div class="form-group"> <label for="exampleInputCity1">GST </label> <input type="text" class="form-control" name="gst" value="<?php if(isset($_GET['edit_id'])) { echo $sqlData['gst'];}?>" placeholder="GST" required> </div> </div> </div> <div class="row"> <div class="col-md-12"> <div class="form-group"> <label for="exampleInputCity1">Address</label> <textarea class="form-control" name="address" placeholder="Retailer Address" required><?php if(isset($_GET['edit_id'])) {echo $sqlData['address'];}?></textarea> </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> </div> <br><br> <div class="col-lg-12 grid-margin stretch-card"> <div class="card"> <div class="card-body"> <h4 class="card-title">Retailer List</h4> <div class="table-responsive"> <table class="table table-striped"> <thead> <tr> <th>S.No.</th> <th>Distributor</th> <th>Name</th> <th>Email</th> <th>Mobile No.</th> <th>Address</th> <th>Action</th> </tr> </thead> <tbody> <?php $i = 1; $sqlEmployee = mysqli_query($cn,"SELECT * FROM `tbl_retailer` where `status`=1 order by name"); while($sqlEmployeeData = mysqli_fetch_array($sqlEmployee)) { $sqlDistributor = mysqli_query($cn,"SELECT * FROM `tbl_distributor` where `id`='".$sqlEmployeeData['distributor_id']."'"); $sqlDistributorData = mysqli_fetch_array($sqlDistributor); ?> <tr> <td><?php echo $i++;?></td> <td><?php echo $sqlDistributorData['name'];?></td> <td><?php echo $sqlEmployeeData['name'];?></td> <td><?php echo $sqlEmployeeData['email'];?></td> <td><?php echo $sqlEmployeeData['mobile'];?></td> <td><?php echo $sqlEmployeeData['address'];?></td> <td> <div class="btn-group dropdown"> <button type="button" class="btn btn-success dropdown-toggle btn-sm" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Action</button> <div class="dropdown-menu"> <a class="dropdown-item" href="?pages=offlineRetailer&edit_id=<?php echo $sqlEmployeeData['id'];?>"><i class="icon-eye"></i> Edit</a> <a class="dropdown-item" href="?pages=offlineRetailer&delete_id=<?php echo $sqlEmployeeData['id'];?>"><i class="icon-eye-blocked"></i>Delete</a> </div> </div> </td> </tr> <?php }?> </tbody> </table> </div> </div> </div> </div>