<html>
<head>
    <meta charset="utf-8"/>
    <title>PRAYATNA - User Login</title>
	<link rel="stylesheet" href="user_style.css">
	<link href="https://fonts.googleapis.com/css2?family=Asap+Condensed&display=swap" rel="stylesheet">
</head>
<body>
<?php
    require('db.php');
    session_start();
    // When form submitted, check and create user session.
    if (isset($_POST['mobile'])) {
        $mobile = stripslashes($_REQUEST['mobile']);    // removes backslashes
        $mobile = mysqli_real_escape_string($con, $mobile);
        // Check user is exist in the database
        //$query    = "SELECT * FROM `user` WHERE mobile='$mobile' AND password='" . md5($password) . "' AND accept=1;" ;
		$query    = "SELECT * FROM `user` WHERE mobile='$mobile'";
        $result = mysqli_query($con, $query) or die(mysql_error());
        $rows = mysqli_num_rows($result);
		$_SESSION['mobile']=$mobile;
        if ($rows == 1) {
			$record = $result->fetch_assoc();
			echo '<form action = "user_forgot_pwd_db.php" class="user_login_form" method = "POST" name = "submitresetform">';
			echo '<div id="reset">';
			echo "<h3>";
			echo "Welcome,". $record['uname'];
			echo "<br>";
			echo "Your secret question is ";
			echo " - ".$record['question'];
			echo "</h3>";
			echo '<input type="text" class = "login-input" id="answer" name="answer" placeholder="Secret Answer" required>
				<h3 class="login-title">USER NEW PASSWORD</h3>
				<input type="password" class="login-input" id="password" name="password" placeholder="New Password" required>
				<br><br><br>';
			echo '<input type="submit" value="RESET" name="submitreset" class="user_login_button">';

            //echo '</form></div>';
            //header("Location: user_add_event.php");
			}
			else {
            echo "<div class='form'>
                  <h3>Mobile number is not registered</h3><br/>
	                  </div>";
			}
	?><p></p>
	<a href="user_login.php"> <input type = "button" value = "LOGIN" class="user_login_button"></a></form></div>
<?php

        } 
	else {
?>
    <div id="login">
    <form class="user_login_form" method="post" name="login">
        <h1 class="login-title">USER RESET PASSWORD</h1>
        <input type="tel" class="login-input" id="mobile" name="mobile" placeholder="Mobile Number" pattern="[0-9]{10}" required>
		<br><br><br>
        <input type="submit" value="RESET" name="submit" class="user_login_button"/>
		<p></p>
		 <a href="user_login.php"> <input type = "button" value = "LOGIN" class="user_login_button"></
		<p></p>
		 <a href="index.html"> <input type = "button" value = "HOME" class="user_login_button"></a>
    </form>
    </div>
<?php
    }
?>
</body>
</html>