<?php session_start();
error_reporting(0);
include_once('includes/config.php');
// Code for User login
if (isset($_POST['submit'])) {
    $username = $_POST['emailid'];
    $cnumber = $_POST['phoneno'];
    $newpassword = md5($_POST['inputPassword']);
    $ret = mysqli_query($con, "SELECT id FROM users WHERE email='$username' and contactno='$cnumber'");
    $num = mysqli_num_rows($ret);
    if ($num > 0) {
        $query = mysqli_query($con, "update users set password='$newpassword' WHERE email='$username' and contactno='$cnumber'");

        echo "<script>alert('Password reset successfully.');</script>";
        echo "<script type='text/javascript'> document.location ='login.php'; </script>";
    } else {
        echo "<script>alert('Invalid Email or Reg Contact Number');</script>";
        echo "<script type='text/javascript'> document.location ='password-recovery.php'; </script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include('includes/head.php'); ?>
<script type="text/javascript">
    function valid() {
        if (document.passwordrecovery.inputPassword.value != document.passwordrecovery.cinputPassword.value) {
            alert("Password and Confirm Password Field do not match  !!");
            document.passwordrecovery.cinputPassword.focus();
            return false;
        }
        return true;
    }
</script>
<style type="text/css">
    input {
        border: solid 1px #000;

    }
</style>

<body class="cnt-home">
    <header class="header-style-1">
        <?php include('includes/top-header.php'); ?>
        <?php include('includes/main-header.php'); ?>
        <?php include('includes/menu-bar.php'); ?>
    </header>

    <!-- Breadcrumb -->
    <div class="breadcrumb mt-2">
        <div class="container">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="index.php">Home</a></li>
                    <li class="breadcrumb-item"><a href="login.php">Login</a></li>
                    <li class="breadcrumb-item active">Password Recovery</li>
                </ol>
            </nav>
        </div>
    </div>

    <!-- Main Content -->
    <div class="body-content outer-top-xs">
        <div class="container">
            <!-- Section-->
            <section class="py-5">
                <div class="container px-4  mt-5">


                    <form method="post" name="passwordrecovery" onSubmit="return valid();">

                        <div class="row mt-3">
                            <div class="col-2">Email Id</div>
                            <div class="col-6"><input type="email" name="emailid" id="emailid" class="form-control"
                                    required>
                            </div>

                        </div>

                        <div class="row mt-3">
                            <div class="col-2">Reg. Contact No.</div>
                            <div class="col-6"><input type="text" name="phoneno" id="phoneno" class="form-control"
                                    required>
                            </div>

                        </div>


                        <div class="row mt-3">
                            <div class="col-2">Password</div>
                            <div class="col-6"><input type="password" name="inputPassword" id="inputPassword"
                                    class="form-control" required></div>
                        </div>

                        <div class="row mt-3">
                            <div class="col-2">Password Recovery</div>
                            <div class="col-6"><input type="password" name="cinputPassword" id="cinputPassword"
                                    class="form-control" required></div>
                        </div>

                        <div class="row mt-3">
                            <div class="col-4">&nbsp;</div>
                            <div class="col-6"><input type="submit" name="submit" id="submit" class="btn btn-primary"
                                    value="Submit" required></div>
                        </div>
                    </form>

                </div>


        </div>
    </div><!-- /.container -->
    </div><!-- /.body-content -->

    <!-- Footer -->
    <?php include('includes/footer.php'); ?>
    <?php include('includes/foot.php'); ?>
</body>

</html>
