<?php
require('include/connection.php');
$msg=0;
$error=0;

 session_start();
 $uID=$_SESSION['uID'];
 $username=$_SESSION['username'];

   if (empty($username)){

       header("location:index.php");
   
   }


$query="SELECT * fROM users_tbl where username='$username'";
$result=mysqli_query($link,$query);
mysqli_num_rows($result);
$row= mysqli_fetch_array($result);

?>

 <!DOCTYPE html>
 <!DOCTYPE html>
<html>
<head>

    <link href="library/bootstrap-5/bootstrap.min.css" rel="stylesheet" />
    <script src="library/bootstrap-5/bootstrap.bundle.min.js"></script>
    <script src="library/dselect.js"></script>
    <link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>

<center>
                	<div class="alert alert-success" role="alert">
                    	<h2><span class="badge badge-secondary">RESET PASSWORD </span></h2>
                        	
                	</div>
            	</center>  

 <div class="container">

  <form action="" method="post">

<?php if($error){?><div class="alert alert-danger"><strong>ERROR</strong>:<?php  echo htmlentities($error); ?> </div><?php } 
else if($msg){?><div class="alert alert-success"><strong>SUCCESSFULLY</strong> : <?php echo htmlentities($msg); ?> </div><?php }?>


            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <label for="email" class="form-label">Add new password </label>
                    <input type="plateNo" class="form-control"  name="newpass" value="" required/>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                <label for="email" class="form-label">Comfirm new password </label>
                    <input type="integer" class="form-control" name="confirmpass" value=""/>
                </div>
                <!-- <div class="col-md-3">&nbsp;</div> -->
            </div>  
             
            <div class="row">
                <div class="col-md-3">&nbsp;</div>
                <div class="col-md-6">
                    <br>
                <center><input type="submit" class="btn btn-primary" name="submit" value="SAVE" />
                    <a href="logout.php"> <button class="btn btn-danger" type="button">LOGOUT</button></a></center>
                </div>
                <!-- <a href="logout.php"> <button class="btn btn-info approve" type="button">LOGOUT</button></a> -->
            </div> 
        
            </div>
    





    <!-- <div class="row">
    <div class="col-md-3">&nbsp;</div>
        <div class="col-md-6">
        <label for="email" class="form-label">Add new password</label>
        </div>  
        <input type="plateNo" class="form-control" id="new password" name="newpass">
    </div>
    
    <div class="row">
        <div class="col-md-6">
        <label for="email" class="form-label">Comfirm new password</label>
        </div>
        <input type="plateNo" class="form-control" id="confirm password" name="confirmpass" >           
    </div> -->
    <!--  -->
  </form>
</div>
</div>
<?php

if (isset($_POST['submit'])) {
   
   $newpass = $_POST['newpass'];
   $confirmpass = $_POST['confirmpass'];
  
       if($newpass!=""  && $confirmpass!=""){
  
      if ($newpass == $confirmpass) {
  
        $hasdnewpass= $newpass;
  
         $mysqli="UPDATE users_tbl SET password ='$hasdnewpass' where uID='$uID' ";
         $sendsql= mysqli_query($link,$mysqli);
         if ($sendsql) {
            header("location:index.php");
         }else {
             $error=" server error the password was not changed";
         }
          
      }else {
         $error="new password and confirmed password din't match";
      }
  
       }else {
         $error="enter new password and confirmed password";
      }
      
   }
  
  ?>


</body>
<html>