<?php require_once("header.php");?>

<?php
if(isset($_POST['send']))
{	
	$sql_check = "SELECT * FROM `sc_users` WHERE `otp` = '".$_POST['otp']."' AND `user_id` = '".$_POST['uid']."'";
    $exe_check = mysqli_query($connection,$sql_check);
    $num_check = mysqli_num_rows($exe_check);
    if($num_check>0)
    {
    	$sql_update = "UPDATE `sc_users` SET `user_status` = 'Active' WHERE `user_id` = '".$_POST['uid']."'";
        $exe_update = mysqli_query($connection,$sql_update);
        
        header("location: registration.php?user_id=".$_POST['uid']);
    }
    else
    {
    	$_SESSION['msg_fail'] = 'Invalid OTP. Plaese try again!';
    	header("location: otp.php?last_id=".$_POST['uid']);
    	exit;
    }
}
?>

			<script language="javascript" type="text/javascript">
    		function form_validation()
    		{
    			if(document.getElementById('otp').value == "")
    			{
    				alert("Please enter otp");
    				document.getElementById('otp').focus();
    				return false;
    			}
    			
    			return true;
    		}
    		</script>

			<!-- page template area start -->
			<section id="about">
				<div class="container mt-0 pb-0 pt-5">
				    <h1 class="title mt-0 mb-0" style="text-align:center;">Registration Step - 2</h1>
				    <h3 class="title mt-0 mb-10" style="text-align:center;">OTP Verification</h3>
					<div class="row">
						<div class="col-md-12">
							<?php if(isset($_SESSION['msg_fail'])) { ?>
							<p style="text-align:center; margin-bottom:10px;"><img src="images/cross.png" alt="" /> <?php echo $_SESSION['msg_fail'];?></p>
							<?php 
							unset($_SESSION['msg_fail']);
							} 
							?>	
							<form id="contact_form" name="contact_form" class="" action="" method="post" onSubmit="return form_validation();">
							<div class="row">
								<div class="col-sm-12">
									<div class="form-group">
										<input name="otp" id="otp" class="form-control" type="tel" placeholder="Enter OTP *">
									</div>
								</div>
							</div>
							<div class="form-group">
								<input type="hidden" name="send" id="send" value="1" />
								<input type="hidden" name="uid" id="uid" value="<?php echo $_GET['last_id'];?>" />
								<p><button type="submit" class="btn btn-flat btn-theme-colored border-left-theme-color-2-4px">Submit</button></p>
							</div>
							</form>
						</div>
					</div>
				</div>
			</section>
			<!-- page template area end -->

<?php require_once("footer.php");?>