<?php 
session_start();
// Connect to the database
require_once('dbconnect.php'); 

// Set username and password variables for this script
$cnum = $_POST['customernum'];
$pwd = $_POST['password'];
 

// Make sure the username and password match, selecting all the client's
// data from the database if it does. Store the data into $clientdata
$clientdata = mysql_query("SELECT * FROM ibank WHERE `customernum` = '$cnum' and `password` = '$pwd'") or die (mysql_error());

// Put the $clientdata query into an array we can work with
$data = mysql_fetch_array($clientdata, MYSQL_ASSOC);

// If the username and password matched, we should have one entry in our
// $clientdata array. If not, we should have 0. So, we can use a simple
// if/else statement
if(mysql_num_rows($clientdata) == 1 && $data['activationkey'] == ''){
	
	// Start a new blank session. This will assign the user's server
	// with a session with an idividual ID
	$_SESSION['accholder'] = $data['accholder'];
	$_SESSION['MM_Username'] = $data['customernum'];
	
	header('Location: index.php');
}
else
{
session_regenerate_id();
	$_SESSION['SESS_FIRSTERRMSG'] = "Invalid account number or password";
	session_write_close();
	header('location: login.html');
	}
			
?>