<?  session_start();  

/*********************************************************
* filename: addUser
* Purpose: Adds and validates a new user to the database.
* Version information
* Date: November 5, 2001
* Copyright notice
***********************************************************/


//**  Include Class definitions   */
require("DB.php");

//** Check that form was filled out completely */
//**  if not, redirect to form and display message */
//echo" first $firstName last $lastName userName $userName pwd $pwd";
if (empty($f) || empty($l) || empty($userName) || empty($pwd))
{
	$blankFields = 1;
	session_register('blankFields');
	header("Location: newUser.php");
	exit;
}

//** Ensure that passwords match, if not, */
//**   redirect to form and display message */
if($pwd != $pwd2){
	$passwordMismatch = 1;
	session_register('passwordMismatch');
	header("Location: newUser.php");
	exit;
}

//** Create instance of DB class and log in to database */
$db = new DB("andromeda","gradinfo");
//$user = new User($first,$last,$userName,$pwd);
$db->connect();

//** Check to make sure that username has not already been used */
//**  if it has, redirect and display message */
  if( $db->checkUser($userName)==1 ){
	$alreadyUsed = 1;
	session_register('alreadyUsed');
	header("Location: newUser.php");
	exit;
  }
	
//** User information is okay, insert user into database */
  $sql = "
	INSERT INTO user
	(first,last,username,password,userType,email)
	VALUES
	(\"$f\",\"$l\",\"$userName\", password(\"$pwd\"), \"$userType\",\"$email\")
	"; 
  $result = @mysql_query($sql) 
		or die("Couldn't execute query.");

  $f = $l = $userName = "";

//** Redirect to form page to add more users */
  header("Location: display.php");
  exit;

?>





