<?php 
session_start();
  include 'lib/dbcon.php';
    include 'lib/functions.php';

        //$action = $_POST['action'];
        $pass = $_POST['password'];
        $c_pass = $_POST['password_confirm'];
        $user  = $_POST['user'];
        $token = $_POST['token'];

        if ($pass!=$c_pass) {
            echo 'Password not matched';
        }
        else{

            $sql_qry = "SELECT * FROM `admin` WHERE username ='$user'";
            $sql_run = mysqli_query($con,$sql_qry);

            if (mysqli_num_rows($sql_run) > 0) {
                $npass = password_hash($pass, PASSWORD_BCRYPT);
                $sql_row = mysqli_fetch_array($sql_run);
                $token .= $token.'-'.'2';
                $db = "UPDATE `admin` SET token = '1', password = '$npass' WHERE username = '".$user."'";
              
                if (mysqli_query($con,$db)) {
    $_SESSION['msg_scs'] = 'Password Updated';
    header("location: reset-password.php");
} 
else {
    $_SESSION['msg_err'] = 'Something Went Wrong Try Later..';
    header("location: reset-password.php");
} 

             }

            
        }
    

    ?>