<?php session_start();
 
require "./conn.php";
if($_POST['v_code'] && $_POST['password'])
{
	$v_code=$_POST['v_code'];
	$password=$_POST['password'];
	
//Sql Query for Sign In...
$sql="select * from tbl_vendor where v_code='$v_code' and status='Active'";

$smt= mysqli_query($conn,$sql);

	if($rs= mysqli_fetch_assoc($smt))
	{
		if(($password)==$rs['password'])
		{
			//Creating Session...
			$_SESSION['user_id'] = $rs['id'];
			$_SESSION['vendor_id'] = $row['id'];   // assuming vendor’s ID is in column `id` of tbl_vendor
			$_SESSION['v_code'] = $rs['v_code'];
			$_SESSION['role'] = $rs['role'];
			$_SESSION['designation'] = $rs['designation'];
		    $_SESSION['name'] = $rs['name'];
		    $_SESSION['email'] = $rs['email'];
		    $_SESSION['mobile'] = $rs['mobile'];
			$_SESSION['password']=$rs['password'];
			$_SESSION['pid']=$rs['pid'];
			$_SESSION['gpid']=$rs['gpid'];
			$_SESSION['pin']=$rs['pin'];
			$_SESSION['status']=$rs['status'];
			session_write_close();
			echo "Login Success";
			}
			else
			{
				echo'Invalid password.'.mysqli_error($conn);
			}
	}

	else
	{
		echo'Invalid ID  or Inactive Account , Please contact MHA';
	}
	
}
else
{
	echo'Please enter a valid User Id and Password.';
}

?>