  <?php include('partials/menu.php'); ?>
 <div class="main-content">
   <div class="wrapper">
     <h1>Add Admin</h1>
     <br></br><br>
     <?php
        if(isset($_SESSION['add'])){
          echo $_SESSION['add'];//displaying SESSION MSG
          unset($_SESSION['add']);//removing session msg
        }
      ?>
      <br><br><br>
     <form action="" method="POST">
       <table class="tbl">
         <tr>
           <td>Full Name</td>
           <td><input type="text" name="full_name" placeholder="Enter Your Full Name"></td>
         </tr>
         <tr>
           <td>Username</td>
           <td><input type="text" name="username" placeholder="Enter Your Username"></td>
         </tr>
         <tr>
           <td>Password</td>
           <td><input type="password" name="password" placeholder="Enter Your Password"></td>
         </tr>
         <tr>
           <td colspan="2">
             <input class="btnsecondary" type="submit" name="submit" value="Add Admin">
           </td>
         </tr>
       </table>
     </form>
   </div>
 </div>
 <?php include('partials/footer.php');?>
 <?php
   //process the value from form and save in the SQLiteDatabase
   //check whether the submit btn is clicked or not
   if(isset($_POST['submit'])){
     // Button clicked
     //get the data from form
     $fullname = mysqli_real_escape_string($conn,$_POST['full_name']);
     $username = mysqli_real_escape_string($conn,$_POST['username']);
     $password = md5($_POST['password']); //pasword encryption with md5
     // sql to insert the data into the database
     $sql = "INSERT INTO tbl_admin SET
        fullname = '$fullname',
        username = '$username',
        password = '$password'
     ";
     //execute query and save data in the database
     $res = mysqli_query($conn, $sql);
     //check whether the data is inserted or not and display appropriate message
      if($res==TRUE){
        // create session var to display message
        $_SESSION['add'] = "Admin Added Successfully";
        //Redirect Page
        header('location:'.SITEURL.'backend/manage-admin.php');
      }else{
        // create session var to display message
        $_SESSION['add'] = "Failed To Add Admin";
        //Redirect Page
        header('location:'.SITEURL.'backend/add-admin.php');
      }
   }

  ?>
