<?php
	session_start();
	include('../db/connection.php');
	date_default_timezone_set("Asia/Kolkata");
	$datetime = date("Y-m-d H:i:s");	
	
	$otp = rand(1011,9999);
	
	if(isset($_POST['phone']))
	{
	    $check_phone_query="SELECT id FROM user WHERE mobile='$_POST[phone]' and deletion = 0";
	    $check_phone_query_row=mysqli_query($conn,$check_phone_query);
	    if($check_phone_query_row->num_rows > 0)
	    {
    		$insert="insert into login_otp_verification (mobile,otp,date) value('$_POST[phone]','$otp','$datetime')";
    		$insert_row=mysqli_query($conn,$insert);
    		if($insert_row==false)
    		{
    			echo "00";
    		}
    		else
    		{
    			$last_id=$conn -> insert_id;
    			$select="select otp from login_otp_verification where active=0 and id=$last_id and mobile='$_POST[phone]'";
    			$select_row=mysqli_query($conn,$select);
    			$select_res=mysqli_fetch_assoc($select_row);
    			if($select_res==true)
    			{
    				echo $select_res['otp'];
    			}
    			else
    			{
    				echo "00";
    			}
    		}
	    }
	    else
	    {
	        echo "33";
	    }
	}
?>