<h1>SignUp</h1>
<p>
<?php
if ( $_POST['Register'] )
{
	$username	= mssql_escape_string( $_POST['username'] );
	$password	= mssql_escape_string( $_POST['password'] );
	$password2	= mssql_escape_string( $_POST['password2'] );
	
	if ( strlen( $username ) > 15 || strlen( $username ) < 3 ) $errors[] = 'Username must be at least 3 characters long and no longer that 15 characters';
	if ( preg_match( '[^A-Za-z0-9]' , $username) ) $errors[] = 'Username must be alphanumeric!';
	if ( strlen( $password ) > 15 || strlen( $password ) < 3 ) $errors[] = 'Password must be at least 3 characters long and no longer that 15 characters';
	if ( $password != $password2 ) $errors[] = 'Passwords do not match';
	
	if ( count( $errors ) == 0 )
	{
		$mssql_link = mssql_connect( 'VADIM-5286\\SQLEXPRESS', 'sa', 'yAsejaZat+u9eNuP' );
		if ( !$mssql_link )
		{
			showMessage( 'info', 'Registration is temporarly offline' );
		}
		else
		{
			$checkUser = mssql_query( "SELECT * FROM Account..tUser WHERE sUserID = '$username';" );
			if ( mssql_num_rows( $checkUser ) == 0 )
			{
				$inserUser = mssql_query( "INSERT INTO Account..tUser (sUserID, sUserPW, sUserName, sUserIP) VALUES ('$username', '$password', '$username', '" . $_SERVER['REMOTE_ADDR'] . "');" );
				mssql_close( $mssql_link );
				if( $inserUser )
				{
					showMessage( 'success', 'Account has been created! Enjoy' );
				}
				else
				{
					die( 'MSSQL Error!' );
				}
			}
			else
			{
				showMessage( 'error', 'Such username is already in use' );
			}
		}
	}
	else
	{
		foreach ( $errors as $myError )
		{
			$errors22 = $myError.'<br />';
		}
		showMessage( 'error', $errors22 );
	}
}
else
{ ?>
<form method="post">
	<table width="400px">
		<tr>
			<td>Username</td>
			<td><input type="text" name="username" /></td>
		</tr>
		<tr>
			<td>Password</td>
			<td><input type="password" name="password" /></td>
		</tr>
		<tr>
			<td>Password confirmation</td>
			<td><input type="password" name="password2" /></td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" name="Register" value="Create Account" /></td>
		</tr>
	</table>
</form>
<?php 
}
?>