<h2></h2>
<?php
$ok=1;
$errormsg=NULL;//  
//Reading from DB

if ($multireg || !mysql_num_rows(mysql_query("select * from users where lastip='$ip'"))) {
	if (isset($_GET['apply'])) {
		if (isset($_GET['nlogin']))
		  if (preg_match("/^([-a-z0-9_-]*)$/i",$_GET['nlogin']))
				if (strlen($_GET['nlogin'])>1 && strlen($_GET['nlogin'])<10)
					if (!mysql_num_rows(mysql_query("select * from users where login='$_GET[nlogin]'"))) 
						$nlogin=$_GET['nlogin'];
					else {$errormsg.="<li>      !</li>";$ok=0;}
				else {$errormsg.="<li>    </li>";$ok=0;}
			else {$errormsg.="<li>   !</li>";$ok=0;}
		else $ok=0;
		
		if (isset($_GET['npassword'])) $npassword=md5($_GET['npassword']);
			else {$errormsg.="<li>   !</li>";$ok=0;} 
		if (isset($_GET['cpassword']))
			if (md5($_GET['cpassword'])!=md5($_GET['npassword'])) {$errormsg.="<li>    !</li>";$ok=0;}else;
		else {$errormsg.="<li>     !</li>";$ok=0;}

		//Registration, insert record in database	
		if ($ok)
			if (mysql_query("insert into users(login,password,email,style) values('$nlogin','$npassword','-','default')")) {
				if (mysql_query("update `styles` set used=used+1 where name='default'"));else echo "    styles<br>";
				echo "<h3 class=bold> ",$nlogin,"  !</h3>
				<form action=index.php method=POST><input type=hidden name=mylogin value='$nlogin'><input type=hidden name=mypassword value='$_GET[npassword]'>
				<input type=submit value=''></form>";	
			}	else echo "<h3 class=bold>     !</h3>";
		else echo "<h3 class=bold></h3>",$errormsg;
	}
	
	else echo "
		<form action=index.php method=GET>
			<input type=hidden name=page value=rgusr>
			<input type=hidden name=apply>
			<table border=0>
			<tr><td align=right>Login</td><td><input type=text name=nlogin value=guest onFocus=nlogin.value=''></td></tr>
			<tr><td align=right>Password</td><td><input type=password name=npassword></td></tr>
			<tr><td align=right>Confirm</td><td><input type=password name=cpassword></td></tr>
			<tr height=100><td align=center colspan=2><input type=submit value=Ok>&nbsp;<input type=reset value=Reset></td></tr>
			</table>
		</form>";
}
else echo "<h3 class=bold>  </h3>        IP";
?>