 <?php include('partials/menu.php'); ?>
 <div class="main-content">
   <div class="wrapper">
     <h1>Update Admin</h1>
     <br><br><br>
     <?php
        //get id of the selected admin
        $id=$_GET['id'];
        //create sql querry to get the details
        $sql="SELECT * FROM tbl_admin WHERE id=$id";
        //execute the querry
        $res=mysqli_query($conn, $sql);
        //check whether the querry is executed or not
        if ($res==TRUE) {
          //CHECK whether data is available or not
          $count = mysqli_num_rows($res);
          //check whether we have admin data or not
          if($count==1){
            //get the details
            $row=mysqli_fetch_assoc($res);
            $full_name = $row['fullname'];
            $username = $row['username'];
          }else{
            //redirect to manage admin page
              header('location:' .SITEURL.'backend/manage-admin.php');
          }
          // code...
        }
      ?>
    <form action="" method="POST">
      <table class="tbl">
        <tr>
          <td>Full Name</td>
          <td><input type="text" name="full_name" value="<?php echo $full_name; ?>"></td>
        </tr>
        <tr>
          <td>Username</td>
           <td><input type="text" name="username" value="<?php echo $username; ?>"></td>
        </tr>

        <tr>
          <td colspan="2">
            <input type="hidden" name="id" value="<?php echo $id; ?>">
            <input class="btnsecondary" type="submit" name="submit" value="update Admin">
          </td>
        </tr>
      </table>
    </form>
   </div>
 </div>
 <?php
    //check whether the submit btn is clicked or not
    if (isset($_POST['submit'])) {
      //echo "BTN CLICKED";
      // get all the values frm form to update
      $id = mysqli_real_escape_string($conn,$_POST['id']);
      $fullname = mysqli_real_escape_string($conn,$_POST['full_name']);
      $username = mysqli_real_escape_string($conn,$_POST['username']);
      //create sql to update admin
      $sql = "UPDATE tbl_admin SET
      fullname = '$fullname',
      username = '$username'
      WHERE id='$id'
      ";
      //execute the querry
      $res = mysqli_query($conn, $sql);
      //check whether the query is executed Successfully or not
     if($res==true)
      {
        //succefully update
        $_SESSION['update'] = "<div class='success'>Admin Updated Successfully.</div>";
        //redirect to manage admin
          header('location:' .SITEURL.'backend/manage-admin.php');
      }else{
        //failed to update admin
          $_SESSION['update'] = "<div class='success'>Admin Updated Successfully.</div>";
          header('location:' .SITEURL.'backend/updateadmin.php');
      }
    }
  ?>
 <?php include('partials/footer.php'); ?>
