<?php
session_start();
require_once('mysql_login.php');
$errorMessage = '';
if(isset($_POST['txtUserId']) && isset($_POST['txtPassword']))
 {
	$userpass = md5($_POST['txtPassword']);
	$username = $_POST['txtUserId'];
	$result = mysql_query("SELECT * FROM user WHERE password='$userpass' AND username='$username'") or die("Couldn't query the user-database.");
	$row_user = mysql_fetch_array($result);
	$num = mysql_result($result, 0); 
	if(!$num)
	{
	$errorMessage = 'Sorry, wrong username / password';
	}
	 else
	  {
	  	$_SESSION['autheticate'] = true;
		$_SESSION['identification'] = $row_user['identification'];
		$_SESSION['admin'] = $row_user['admin'];
		flush();
		ob_flush();
		//header('Location: ../test.php');
		echo "<meta http-equiv = \"refresh\" content = \"1; URL=index.php\">";
		exit;
	}
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<p align = "center">Login is required to<br> make any changes</p>
<form action="" method="post" name="frmLogin" id="frmLogin">
 <table width="170" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
   <td width="82">Username:</td>
   <td width="140"><input name="txtUserId" type="text" id="txtUserId" size="12"></td>
   </tr>
  	<tr>
   <td width="82">Password:</td>
   <td><input name="txtPassword" type="password" id="txtPassword" size="12"></td>
   </tr>
   </tr>
    <td width="82">&nbsp;</td>
   <td width="140"><input name="btnLogin" type="submit" id="btnLogin" value="Login" ></td>
  	</tr>
 </table>
 <div align="left"><br> 
   <font color = "#990099" size = "2.5" family = "verdana">Or Create a<br><a href = "user_apply.php"> new Account </a> </font>
 </div>
</form>
</body>
</html>