<?php
if(isset($_REQUEST['login'])){
$conn=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_mt");
$sqlst="select title_names,positions,usernames,full_names from users where usernames='".$_REQUEST['username'].
"' and passwords='".$_REQUEST['password']."' ";

$qry=mysqli_query($conn,$sqlst);
if(mysqli_num_rows($qry)>1){
header("location:index.php?errors=multiple users");}

if(mysqli_num_rows($qry)==0){
header("location:index.php?errors=invalid user name/ password");}

if(mysqli_num_rows($qry)==1){
$rst=mysqli_fetch_row($qry);

session_start();
$_SESSION['titles']=$rst[0];
$_SESSION['positions']=$rst[1];
$_SESSION['usernames']=$rst[2];
$_SESSION['fnames']=$rst[3];
$months=date('m');
$days=date('t');
$years=date('Y');

if($starts==0 || $starts==''){
$starts=$years."-".$months."-01";}
if($ends==0 || $ends==''){
$ends=$years."-".$months."-".$days;}


$sqlst="select distinct segments from accs where user_names='".$_REQUEST['username']."' ";
$qry=mysqli_query($conn,$sqlst);
while($rst=mysqli_fetch_row($qry)){

if($rst[0]=='primarys'){
$usstates=1;}

if($usstates==1){
$hdr="location:maindash.php?rpsty=agentsummarys&starts=".$starts."&ends=".$ends."&regions=all&agents=All&territorys=0&zones=All&regions=All";}

header($hdr);
}
}
}

?>