<?php
session_start();
ob_start();
include "connect.inc.php";
$user = $_POST[usr];
$pd = $_POST[pwd];
$sqlCheck = "select  uname,nameofuser,status from sysuser where uname = '$user' and pwd = password('$pd')";
echo $sqlCheck;
$qryCheck = mysql_query($sqlCheck);
$numCheck = mysql_num_rows($qryCheck);
if($numCheck == 1)
{
echo "User Valid";

$resultCheck = mysql_fetch_array($qryCheck);
$myuser = $user;
$username = $resultCheck['uname'];
$nameuser = $resultCheck['nameofuser'];
$status =  $resultCheck['status'];
	$_SESSION['myusername'] = $myuser;
	$_SESSION['usname'] = $nameuser;
	$_SESSION['status'] = $status;
	
	//echo $_SESSION['myusername'];
	//echo $_SESSION['usname'];
	//echo $_SESSION['status'];
	
	
	$dnow = date("Y-m-d H:i:s");
	require_once("usr_function.php");
	updatetime($myuser);
	header("Location:main.php");
	$tlog = $userName." Log in success";
	require_once("usr_function.php");
	addLog($_SESSION['myusername'],$tlog);
	mysql_close($link);
	////
}
else
{
	header("Location:index.php?err=1");
	/// add logfile
	$tlog = $user." try to access";
	require_once("usr_function.php");
	$u = "Unknow";
	addLog($u,$tlog);
	mysql_close($link);
	////
}
?>